aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorlloyd <[email protected]>2009-11-29 13:14:33 +0000
committerlloyd <[email protected]>2009-11-29 13:14:33 +0000
commit70ba49797c45db0c28a803341570f7d832c16e7d (patch)
tree246070d469b4df6528e85e61b05a9b892ba08736 /doc
parent68500fd6d481ebbb2474ca20d233cae80ec1a8eb (diff)
parent4a94c35f8c9b73666a53a14a9b0a2ee50a742e89 (diff)
propagate from branch 'net.randombit.botan' (head ac4d8fecb28374d06094da3457aa1e23f77dfa52)
to branch 'net.randombit.botan.c++0x' (head 00f0eecf3374a14b6ab907bd235488f902608de4)
Diffstat (limited to 'doc')
-rw-r--r--doc/examples/read_ssh.cpp119
-rw-r--r--doc/log.txt4
2 files changed, 123 insertions, 0 deletions
diff --git a/doc/examples/read_ssh.cpp b/doc/examples/read_ssh.cpp
new file mode 100644
index 000000000..a88306caa
--- /dev/null
+++ b/doc/examples/read_ssh.cpp
@@ -0,0 +1,119 @@
+/*
+* Example of reading SSH2 format public keys (see RFC 4716)
+*/
+
+#include <fstream>
+#include <botan/x509_key.h>
+#include <botan/filters.h>
+#include <botan/loadstor.h>
+#include <botan/rsa.h>
+#include <botan/dsa.h>
+
+using namespace Botan;
+
+u32bit read_u32bit(Pipe& pipe)
+ {
+ byte out[4] = { 0 };
+ pipe.read(out, 4);
+ u32bit len = load_be<u32bit>(out, 0);
+ if(len > 10000)
+ throw Decoding_Error("Huge size in read_u32bit, something went wrong");
+ return len;
+ }
+
+std::string read_string(Pipe& pipe)
+ {
+ u32bit len = read_u32bit(pipe);
+
+ std::string out(len, 'X');
+ pipe.read(reinterpret_cast<byte*>(&out[0]), len);
+ return out;
+ }
+
+BigInt read_bigint(Pipe& pipe)
+ {
+ u32bit len = read_u32bit(pipe);
+
+ SecureVector<byte> buf(len);
+ pipe.read(&buf[0], len);
+ return BigInt::decode(buf);
+ }
+
+Public_Key* read_ssh_pubkey(const std::string& file)
+ {
+ std::ifstream in(file.c_str());
+
+ const std::string ssh_header = "---- BEGIN SSH2 PUBLIC KEY ----";
+ const std::string ssh_trailer = "---- END SSH2 PUBLIC KEY ----";
+
+ std::string hex_bits;
+
+ std::string line;
+ std::getline(in, line);
+
+ if(line != ssh_header)
+ return 0;
+
+ while(in.good())
+ {
+ std::getline(in, line);
+
+ if(line.find("Comment: ") == 0)
+ {
+ while(line[line.size()-1] == '\\')
+ std::getline(in, line);
+ std::getline(in, line);
+ }
+
+ if(line == ssh_trailer)
+ break;
+
+ hex_bits += line;
+ }
+
+ Pipe pipe(new Base64_Decoder);
+ pipe.process_msg(hex_bits);
+
+ std::string key_type = read_string(pipe);
+
+ if(key_type != "ssh-rsa" && key_type != "ssh-dss")
+ return 0;
+
+ if(key_type == "ssh-rsa")
+ {
+ BigInt e = read_bigint(pipe);
+ BigInt n = read_bigint(pipe);
+ return new RSA_PublicKey(n, e);
+ }
+ else if(key_type == "ssh-dss")
+ {
+ BigInt p = read_bigint(pipe);
+ BigInt q = read_bigint(pipe);
+ BigInt g = read_bigint(pipe);
+ BigInt y = read_bigint(pipe);
+
+ return new DSA_PublicKey(DL_Group(p, q, g), y);
+ }
+
+ return 0;
+ }
+
+#include <botan/init.h>
+#include <iostream>
+
+int main()
+ {
+ LibraryInitializer init;
+
+ Public_Key* key = read_ssh_pubkey("dsa.ssh");
+
+ if(key == 0)
+ {
+ std::cout << "Failed\n";
+ return 1;
+ }
+
+ std::cout << X509::PEM_encode(*key);
+
+ return 0;
+ }
diff --git a/doc/log.txt b/doc/log.txt
index 57c1a22a1..c0c87028c 100644
--- a/doc/log.txt
+++ b/doc/log.txt
@@ -1,4 +1,8 @@
+* 1.9.4-dev, ????-??-??
+ - Greatly improve the Win32 installer
+ - Several fixes for Visual C++ debug builds
+
* 1.9.3, 2009-11-19
- Add new AES implementation using Intel's AES instruction intrinsics
- Add an implementation of format preserving encryption