aboutsummaryrefslogtreecommitdiffstats
path: root/doc/examples
diff options
context:
space:
mode:
Diffstat (limited to 'doc/examples')
-rw-r--r--doc/examples/dsa_kgen.cpp20
-rw-r--r--doc/examples/new_engine.cpp3
-rw-r--r--doc/examples/tls_client.cpp18
-rw-r--r--doc/examples/tls_server.cpp17
-rw-r--r--doc/examples/x509info.cpp123
5 files changed, 40 insertions, 141 deletions
diff --git a/doc/examples/dsa_kgen.cpp b/doc/examples/dsa_kgen.cpp
index e949ae54a..fe3157370 100644
--- a/doc/examples/dsa_kgen.cpp
+++ b/doc/examples/dsa_kgen.cpp
@@ -2,22 +2,10 @@
* (C) 2009 Jack Lloyd
*
* Distributed under the terms of the Botan license
-*/
-
-
-/**
-Generate a 1024 bit DSA key and put it into a file. The public key
-format is that specified by X.509, while the private key format is
-PKCS #8.
-
-The domain parameters are the ones specified as the Java default DSA
-parameters. There is nothing special about these, it's just the only
-1024-bit DSA parameter set that's included in Botan at the time of
-this writing. The application always reads/writes all of the domain
-parameters to/from the file, so a new set could be used without any
-problems. We could generate a new set for each key, or read a set of
-DSA params from a file and use those, but they mostly seem like
-needless complications.
+*
+* Generate a 1024 bit DSA key and put it into a file. The public key
+* format is that specified by X.509, while the private key format is
+* PKCS #8.
*/
#include <iostream>
diff --git a/doc/examples/new_engine.cpp b/doc/examples/new_engine.cpp
index 4a2339bef..42e5dbe33 100644
--- a/doc/examples/new_engine.cpp
+++ b/doc/examples/new_engine.cpp
@@ -39,7 +39,8 @@ class XOR_Cipher : public StreamCipher
void key_schedule(const byte key[], size_t length)
{
- mask.set(key, length);
+ mask.resize(length);
+ copy_mem(&mask[0], key, length);
}
SecureVector<byte> mask;
diff --git a/doc/examples/tls_client.cpp b/doc/examples/tls_client.cpp
index 854cb3b28..10ead20cc 100644
--- a/doc/examples/tls_client.cpp
+++ b/doc/examples/tls_client.cpp
@@ -15,6 +15,22 @@ using namespace Botan;
#include <iostream>
#include <memory>
+class Client_TLS_Policy : public TLS_Policy
+ {
+ public:
+ bool check_cert(const std::vector<X509_Certificate>& certs) const
+ {
+ for(size_t i = 0; i != certs.size(); ++i)
+ {
+ std::cout << certs[i].to_string();
+ }
+
+ std::cout << "Warning: not checking cert signatures\n";
+
+ return true;
+ }
+ };
+
int main(int argc, char* argv[])
{
if(argc != 2 && argc != 3)
@@ -37,7 +53,7 @@ int main(int argc, char* argv[])
std::auto_ptr<Botan::RandomNumberGenerator> rng(
Botan::RandomNumberGenerator::make_rng());
- TLS_Policy policy;
+ Client_TLS_Policy policy;
TLS_Client tls(std::tr1::bind(&Socket::read, std::tr1::ref(sock), _1, _2),
std::tr1::bind(&Socket::write, std::tr1::ref(sock), _1, _2),
diff --git a/doc/examples/tls_server.cpp b/doc/examples/tls_server.cpp
index e45a24759..91bb9ffbf 100644
--- a/doc/examples/tls_server.cpp
+++ b/doc/examples/tls_server.cpp
@@ -19,6 +19,21 @@ using namespace Botan;
#include <iostream>
#include <memory>
+class Server_TLS_Policy : public TLS_Policy
+ {
+ public:
+ bool check_cert(const std::vector<X509_Certificate>& certs) const
+ {
+ for(size_t i = 0; i != certs.size(); ++i)
+ {
+ std::cout << certs[i].to_string();
+ }
+
+ std::cout << "Warning: not checking cert signatures\n";
+
+ return true;
+ }
+ };
int main(int argc, char* argv[])
{
@@ -44,7 +59,7 @@ int main(int argc, char* argv[])
Unix_Server_Socket listener(port);
- TLS_Policy policy;
+ Server_TLS_Policy policy;
while(true)
{
diff --git a/doc/examples/x509info.cpp b/doc/examples/x509info.cpp
index 52cc4afbd..b22b4ebd8 100644
--- a/doc/examples/x509info.cpp
+++ b/doc/examples/x509info.cpp
@@ -7,48 +7,9 @@
#include <botan/botan.h>
#include <botan/x509cert.h>
-#include <botan/oids.h>
using namespace Botan;
#include <iostream>
-#include <iterator>
-#include <algorithm>
-
-namespace {
-
-std::string to_hex(const SecureVector<byte>& bin)
- {
- Pipe pipe(new Hex_Encoder);
- pipe.process_msg(bin);
- if(pipe.remaining())
- return pipe.read_all_as_string();
- else
- return "(none)";
- }
-
-void do_print(const std::string& what,
- const std::vector<std::string>& vals)
- {
- if(vals.size() == 0)
- return;
-
- std::cout << " " << what << ": ";
- std::copy(vals.begin(), vals.end(),
- std::ostream_iterator<std::string>(std::cout, " "));
- std::cout << "\n";
- }
-
-void do_subject(const X509_Certificate& cert, const std::string& what)
- {
- do_print(what, cert.subject_info(what));
- }
-
-void do_issuer(const X509_Certificate& cert, const std::string& what)
- {
- do_print(what, cert.issuer_info(what));
- }
-
-}
int main(int argc, char* argv[])
{
@@ -63,89 +24,7 @@ int main(int argc, char* argv[])
try {
X509_Certificate cert(argv[1]);
- std::cout << "Version: " << cert.x509_version() << std::endl;
-
- std::cout << "Subject" << std::endl;
- do_subject(cert, "Name");
- do_subject(cert, "Email");
- do_subject(cert, "Organization");
- do_subject(cert, "Organizational Unit");
- do_subject(cert, "Locality");
- do_subject(cert, "State");
- do_subject(cert, "Country");
- do_subject(cert, "IP");
- do_subject(cert, "DNS");
- do_subject(cert, "URI");
- do_subject(cert, "PKIX.XMPPAddr");
-
- std::cout << "Issuer" << std::endl;
- do_issuer(cert, "Name");
- do_issuer(cert, "Email");
- do_issuer(cert, "Organization");
- do_issuer(cert, "Organizational Unit");
- do_issuer(cert, "Locality");
- do_issuer(cert, "State");
- do_issuer(cert, "Country");
- do_issuer(cert, "IP");
- do_issuer(cert, "DNS");
- do_issuer(cert, "URI");
-
- std::cout << "Validity" << std::endl;
-
- std::cout << " Not before: " << cert.start_time() << std::endl;
- std::cout << " Not after: " << cert.end_time() << std::endl;
-
- std::cout << "Constraints" << std::endl;
- Key_Constraints constraints = cert.constraints();
- if(constraints == NO_CONSTRAINTS)
- std::cout << "No constraints" << std::endl;
- else
- {
- if(constraints & DIGITAL_SIGNATURE)
- std::cout << " Digital Signature\n";
- if(constraints & NON_REPUDIATION)
- std::cout << " Non-Repuidation\n";
- if(constraints & KEY_ENCIPHERMENT)
- std::cout << " Key Encipherment\n";
- if(constraints & DATA_ENCIPHERMENT)
- std::cout << " Data Encipherment\n";
- if(constraints & KEY_AGREEMENT)
- std::cout << " Key Agreement\n";
- if(constraints & KEY_CERT_SIGN)
- std::cout << " Cert Sign\n";
- if(constraints & CRL_SIGN)
- std::cout << " CRL Sign\n";
- }
-
- std::vector<std::string> policies = cert.policies();
- if(policies.size())
- {
- std::cout << "Policies: " << std::endl;
- for(u32bit j = 0; j != policies.size(); j++)
- std::cout << " " << policies[j] << std::endl;
- }
-
- std::vector<std::string> ex_constraints = cert.ex_constraints();
- if(ex_constraints.size())
- {
- std::cout << "Extended Constraints: " << std::endl;
- for(u32bit j = 0; j != ex_constraints.size(); j++)
- std::cout << " " << ex_constraints[j] << std::endl;
- }
-
- std::cout << "Signature algorithm: " <<
- OIDS::lookup(cert.signature_algorithm().oid) << std::endl;
-
- std::cout << "Serial: "
- << to_hex(cert.serial_number()) << std::endl;
- std::cout << "Authority keyid: "
- << to_hex(cert.authority_key_id()) << std::endl;
- std::cout << "Subject keyid: "
- << to_hex(cert.subject_key_id()) << std::endl;
-
- X509_PublicKey* pubkey = cert.subject_public_key();
- std::cout << "Public Key:\n" << X509::PEM_encode(*pubkey);
- delete pubkey;
+ std::cout << cert.to_string();
}
catch(std::exception& e)
{