X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=xmltooling%2Fsecurity%2FBasicX509Credential.h;h=b6accbe88450b43b8e2d762d9f12b38484eb4877;hb=10f9e25bb2f29ec48303b02352166754157100e5;hp=6225f69eb136834efc0b006155aef7e7f41078ba;hpb=6505807a62569ce65803b448b07a6872c6af2512;p=shibboleth%2Fcpp-xmltooling.git diff --git a/xmltooling/security/BasicX509Credential.h b/xmltooling/security/BasicX509Credential.h index 6225f69..b6accbe 100644 --- a/xmltooling/security/BasicX509Credential.h +++ b/xmltooling/security/BasicX509Credential.h @@ -24,13 +24,10 @@ #define __xmltooling_basicx509cred_h__ #include +#include #include -namespace xmlsignature { - class XMLTOOL_API KeyInfo; -}; - namespace xmltooling { /** @@ -56,6 +53,9 @@ namespace xmltooling { /** The private/secret key/keypair. */ XSECCryptoKey* m_key; + /** Key names (derived from credential, KeyInfo, or both). */ + std::set m_keyNames; + /** The X.509 certificate chain. */ std::vector m_xseccerts; @@ -79,6 +79,68 @@ namespace xmltooling { public: virtual ~BasicX509Credential(); + const char* getAlgorithm() const { + if (m_key) { + switch (m_key->getKeyType()) { + case XSECCryptoKey::KEY_RSA_PRIVATE: + case XSECCryptoKey::KEY_RSA_PUBLIC: + case XSECCryptoKey::KEY_RSA_PAIR: + return "RSA"; + + case XSECCryptoKey::KEY_DSA_PRIVATE: + case XSECCryptoKey::KEY_DSA_PUBLIC: + case XSECCryptoKey::KEY_DSA_PAIR: + return "DSA"; + + case XSECCryptoKey::KEY_HMAC: + return "HMAC"; + + case XSECCryptoKey::KEY_SYMMETRIC: { + XSECCryptoSymmetricKey* skey = static_cast(m_key); + switch (skey->getSymmetricKeyType()) { + case XSECCryptoSymmetricKey::KEY_3DES_192: + return "DESede"; + case XSECCryptoSymmetricKey::KEY_AES_128: + return "AES"; + case XSECCryptoSymmetricKey::KEY_AES_192: + return "AES"; + case XSECCryptoSymmetricKey::KEY_AES_256: + return "AES"; + } + } + } + } + return NULL; + } + + unsigned int getKeySize() const { + if (m_key) { + switch (m_key->getKeyType()) { + case XSECCryptoKey::KEY_RSA_PRIVATE: + case XSECCryptoKey::KEY_RSA_PUBLIC: + case XSECCryptoKey::KEY_RSA_PAIR: { + XSECCryptoKeyRSA* rkey = static_cast(m_key); + return rkey->getLength(); + } + + case XSECCryptoKey::KEY_SYMMETRIC: { + XSECCryptoSymmetricKey* skey = static_cast(m_key); + switch (skey->getSymmetricKeyType()) { + case XSECCryptoSymmetricKey::KEY_3DES_192: + return 192; + case XSECCryptoSymmetricKey::KEY_AES_128: + return 128; + case XSECCryptoSymmetricKey::KEY_AES_192: + return 192; + case XSECCryptoSymmetricKey::KEY_AES_256: + return 256; + } + } + } + } + return 0; + } + XSECCryptoKey* getPrivateKey() const { if (m_key) { XSECCryptoKey::KeyType type = m_key->getKeyType(); @@ -96,19 +158,17 @@ namespace xmltooling { } return NULL; } + + const std::set& getKeyNames() const { + return m_keyNames; + } - std::vector::size_type getKeyNames(std::vector& results) const; - - const xmlsignature::KeyInfo* getKeyInfo(bool compact=false) const { - return compact ? m_compactKeyInfo : (m_keyInfo ? m_keyInfo : m_compactKeyInfo); + xmlsignature::KeyInfo* getKeyInfo(bool compact=false) const { + if (compact || !m_keyInfo) + return m_compactKeyInfo ? m_compactKeyInfo->cloneKeyInfo() : NULL; + return m_keyInfo->cloneKeyInfo(); } - /** - * Gets an immutable collection of certificates in the entity's trust chain. The entity certificate is contained - * within this list. No specific ordering of the certificates is guaranteed. - * - * @return a certificate chain - */ const std::vector& getEntityCertificateChain() const { return m_xseccerts; }