Browse Source

extract public key from ceritificate

pull/118/head
orignal 10 years ago
parent
commit
b399d45d66
  1. 20
      Reseed.cpp
  2. 9
      Reseed.h
  3. 16
      Signature.h

20
Reseed.cpp

@ -375,6 +375,7 @@ namespace data
signature.SkipAll(); signature.SkipAll();
// issuer // issuer
std::string name;
CryptoPP::BERSequenceDecoder issuer (tbsCert); CryptoPP::BERSequenceDecoder issuer (tbsCert);
{ {
CryptoPP::BERSetDecoder c (issuer); c.SkipAll(); CryptoPP::BERSetDecoder c (issuer); c.SkipAll();
@ -388,9 +389,7 @@ namespace data
{ {
CryptoPP::BERGeneralDecoder ident(attributes, CryptoPP::OBJECT_IDENTIFIER); CryptoPP::BERGeneralDecoder ident(attributes, CryptoPP::OBJECT_IDENTIFIER);
ident.SkipAll (); ident.SkipAll ();
std::string name;
CryptoPP::BERDecodeTextString (attributes, name, CryptoPP::UTF8_STRING); CryptoPP::BERDecodeTextString (attributes, name, CryptoPP::UTF8_STRING);
LogPrint (eLogInfo, "Issuer name: ", name);
} }
} }
} }
@ -403,6 +402,23 @@ namespace data
subject.SkipAll(); subject.SkipAll();
// public key // public key
CryptoPP::BERSequenceDecoder publicKey (tbsCert); CryptoPP::BERSequenceDecoder publicKey (tbsCert);
{
CryptoPP::BERSequenceDecoder ident (publicKey);
ident.SkipAll ();
CryptoPP::BERGeneralDecoder key (publicKey, CryptoPP::BIT_STRING);
key.Skip (1); // FIXME: probably bug in crypto++
CryptoPP::BERSequenceDecoder keyPair (key);
CryptoPP::Integer n;
n.BERDecode (keyPair);
if (name.length () > 0)
{
PublicKey value;
n.Encode (value, 512);
m_SigningKeys[name] = value;
}
else
LogPrint (eLogWarning, "Unknown issuer. Skipped");
}
publicKey.SkipAll(); publicKey.SkipAll();
tbsCert.SkipAll(); tbsCert.SkipAll();

9
Reseed.h

@ -4,6 +4,8 @@
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <vector> #include <vector>
#include <map>
#include "Identity.h"
namespace i2p namespace i2p
{ {
@ -12,6 +14,8 @@ namespace data
class Reseeder class Reseeder
{ {
typedef Tag<512> PublicKey;
public: public:
Reseeder(); Reseeder();
@ -28,7 +32,10 @@ namespace data
int ProcessSU3Stream (std::istream& s); int ProcessSU3Stream (std::istream& s);
bool FindZipDataDescriptor (std::istream& s); bool FindZipDataDescriptor (std::istream& s);
private:
std::map<std::string, PublicKey> m_SigningKeys;
}; };
} }
} }

16
Signature.h

@ -244,10 +244,6 @@ namespace crypto
m_PublicKey.Initialize (CryptoPP::Integer (signingKey, keyLen), CryptoPP::Integer (rsae)); m_PublicKey.Initialize (CryptoPP::Integer (signingKey, keyLen), CryptoPP::Integer (rsae));
} }
RSAVerifier (const CryptoPP::RSA::PublicKey& publicKey): m_PublicKey (publicKey)
{
}
bool Verify (const uint8_t * buf, size_t len, const uint8_t * signature) const bool Verify (const uint8_t * buf, size_t len, const uint8_t * signature) const
{ {
typename CryptoPP::RSASS<CryptoPP::PKCS1v15, Hash>::Verifier verifier (m_PublicKey); typename CryptoPP::RSASS<CryptoPP::PKCS1v15, Hash>::Verifier verifier (m_PublicKey);
@ -306,10 +302,6 @@ namespace crypto
RSASHA2562048Verifier (const uint8_t * signingKey): RSAVerifier (signingKey) RSASHA2562048Verifier (const uint8_t * signingKey): RSAVerifier (signingKey)
{ {
} }
RSASHA2562048Verifier (const CryptoPP::RSA::PublicKey& publicKey): RSAVerifier (publicKey)
{
}
}; };
class RSASHA2562048Signer: public RSASigner<CryptoPP::SHA256> class RSASHA2562048Signer: public RSASigner<CryptoPP::SHA256>
@ -331,10 +323,6 @@ namespace crypto
RSASHA3843072Verifier (const uint8_t * signingKey): RSAVerifier (signingKey) RSASHA3843072Verifier (const uint8_t * signingKey): RSAVerifier (signingKey)
{ {
} }
RSASHA3843072Verifier (const CryptoPP::RSA::PublicKey& publicKey): RSAVerifier (publicKey)
{
}
}; };
class RSASHA3843072Signer: public RSASigner<CryptoPP::SHA384> class RSASHA3843072Signer: public RSASigner<CryptoPP::SHA384>
@ -356,10 +344,6 @@ namespace crypto
RSASHA5124096Verifier (const uint8_t * signingKey): RSAVerifier (signingKey) RSASHA5124096Verifier (const uint8_t * signingKey): RSAVerifier (signingKey)
{ {
} }
RSASHA5124096Verifier (const CryptoPP::RSA::PublicKey& publicKey): RSAVerifier (publicKey)
{
}
}; };
class RSASHA5124096Signer: public RSASigner<CryptoPP::SHA512> class RSASHA5124096Signer: public RSASigner<CryptoPP::SHA512>

Loading…
Cancel
Save