Mixe for Privacy and Anonymity in the Internet
CASignature.hpp
Go to the documentation of this file.
1 /*
2 Copyright (c) 2000, The JAP-Team
3 All rights reserved.
4 Redistribution and use in source and binary forms, with or without modification,
5 are permitted provided that the following conditions are met:
6 
7  - Redistributions of source code must retain the above copyright notice,
8  this list of conditions and the following disclaimer.
9 
10  - Redistributions in binary form must reproduce the above copyright notice,
11  this list of conditions and the following disclaimer in the documentation and/or
12  other materials provided with the distribution.
13 
14  - Neither the name of the University of Technology Dresden, Germany nor the names of its contributors
15  may be used to endorse or promote products derived from this software without specific
16  prior written permission.
17 
18 
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS
20 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21 AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS
22 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24 OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
27 */
28 #ifndef __CASIGNATURE__
29 #define __CASIGNATURE__
30 #if !defined ONLY_LOCAL_PROXY || defined INCLUDE_MIDDLE_MIX
31 #define SIGKEY_XML 1
32 #define SIGKEY_PKCS12 2
33 #define SHA1_REFERENCE "http://www.w3.org/2000/09/xmldsig#sha1"
34 #define DSA_SHA1_REFERENCE "http://www.w3.org/2000/09/xmldsig#dsa-sha1"
35 #define RSA_SHA1_REFERENCE "http://www.w3.org/2000/09/xmldsig#rsa-sha1"
36 #define ECDSA_SHA1_REFERENCE "http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha1"
37 #include "CACertStore.hpp"
38 class CASSLContext;
39 
41  {
42  public:
43  CASignature();
44  ~CASignature();
45  CASignature* clone();
47  SINT32 setSignKey(const UINT8* buff,UINT32 len,UINT32 type,const char* passwd=NULL);
48  SINT32 setSignKey(const DOMNode* node,UINT32 type,const char* passwd=NULL);
50  SINT32 getSignKey(DOMElement* & node,XERCES_CPP_NAMESPACE::DOMDocument* doc);
51  SINT32 sign(const UINT8* const in,UINT32 inlen,UINT8* sig,UINT32* siglen) const;
52  //SINT32 signXML(DOMNode* node,CACertStore* pIncludeCerts=NULL);
53  //SINT32 signXML(UINT8* in,UINT32 inlen,UINT8* out,UINT32* outlen,CACertStore* pIncludeCerts=NULL);
58  SINT32 setVerifyKey(const DOMElement* xmlKey);
62 
63  //SINT32 verify(UINT8* in,UINT32 inlen,UINT8* sig,UINT32 siglen);
64  //SINT32 verifyXML(const UINT8* const in,UINT32 inlen);
65  SINT32 verifyXML(DOMNode* node,CACertStore* pTrustedCerts=NULL);
66  SINT32 getSignatureSize() const;
67  SINT32 encodeRS(UINT8* out,UINT32* outLen,const DSA_SIG* const pdsaSig) const;
68 
79  SINT32 decodeRS(const UINT8* const in, const UINT32 inLen, DSA_SIG* pDsaSig) const;
80  SINT32 verify(const UINT8* const in,UINT32 inlen,DSA_SIG* const dsaSig) const;
81 
93  SINT32 verifyDER(UINT8* in, UINT32 inlen, const UINT8 * dsaSig, const UINT32 sigLen);
94 
95  //MultiCert
96  SINT32 verify(UINT8* in, UINT32 inLen, UINT8* sig, const UINT32 sigLen);
97  bool isDSA() const;
98  bool isRSA() const;
99 #ifdef HAVE_ECC
100  bool isECDSA() const;
101 #endif //ECC
103 
104  friend class CASSLContext;
105  private:
106  DSA* m_pDSA;
107  DSA* getDSA(){return m_pDSA;}
108  RSA* m_pRSA;
109  RSA* getRSA(){ return m_pRSA; }
110 
111  SINT32 parseSignKeyXML(const UINT8* buff,UINT32 len);
112  SINT32 sign(const UINT8* const in,UINT32 inlen,DSA_SIG** dsaSig) const;
113 
114  //MultiCert
115  //friend class CAMultiSignature;
116  SINT32 signRSA(const UINT8* dgst, const UINT32 dgstLen, UINT8* sig, UINT32* sigLen) const;
117  SINT32 verifyRSA(const UINT8* dgst, const UINT32 dgstLen, UINT8* sig, UINT32 sigLen) const;
118  SINT32 verifyDSA(const UINT8* dgst, const UINT32 dgstLen, UINT8* sig, UINT32 sigLen) const;
119 #ifdef HAVE_ECC
120  EC_KEY* m_pEC;
121  EC_KEY* getECKey(){ return m_pEC; }
122  SINT32 signECDSA(const UINT8* dgst, const UINT32 dgstLen, UINT8* sig, UINT32* sigLen) const;
123  SINT32 verifyECDSA(const UINT8* dgst, const UINT32 dgstLen, UINT8* sig, UINT32 sigLen) const;
124 
125 #endif //ECC
126 
127  };
128 #endif
129 #endif //ONLY_LOCAL_PROXY
signed int SINT32
Definition: basetypedefs.h:132
unsigned char UINT8
Definition: basetypedefs.h:135
unsigned int UINT32
Definition: basetypedefs.h:131
friend class CASSLContext
SINT32 verify(const UINT8 *const in, UINT32 inlen, DSA_SIG *const dsaSig) const
bool isDSA() const
SINT32 verifyDSA(const UINT8 *dgst, const UINT32 dgstLen, UINT8 *sig, UINT32 sigLen) const
SINT32 getVerifyKey(CACertificate **)
Get the public key as XML encoded X509 certificate.
SINT32 verifyRSA(const UINT8 *dgst, const UINT32 dgstLen, UINT8 *sig, UINT32 sigLen) const
SINT32 verifyDER(UINT8 *in, UINT32 inlen, const UINT8 *dsaSig, const UINT32 sigLen)
Verifies an ASN.1 DER encoded SHA1-DSA signature.
SINT32 encodeRS(UINT8 *out, UINT32 *outLen, const DSA_SIG *const pdsaSig) const
UINT8 * getSignatureMethod()
RSA * getRSA()
SINT32 generateSignKey(UINT32 size)
Definition: CASignature.cpp:90
CASignature * clone()
Definition: CASignature.cpp:66
SINT32 signRSA(const UINT8 *dgst, const UINT32 dgstLen, UINT8 *sig, UINT32 *sigLen) const
SINT32 decodeRS(const UINT8 *const in, const UINT32 inLen, DSA_SIG *pDsaSig) const
Converts a DSA signature from the XML Signature format to the openSSL R/S BigNumber format.
SINT32 setSignKey(const UINT8 *buff, UINT32 len, UINT32 type, const char *passwd=NULL)
SINT32 parseSignKeyXML(const UINT8 *buff, UINT32 len)
SINT32 getSignatureSize() const
SINT32 setVerifyKey(CACertificate *pCert)
Set the key for signature testing to the one include in pCert.
SINT32 verifyXML(DOMNode *node, CACertStore *pTrustedCerts=NULL)
Verifies a XML Signature under node root.
SINT32 getVerifyKeyHash(UINT8 *buff, UINT32 *len)
Calculates a SHA hash of the public key, which is represented as SubjectPublicKeyInfo.
bool isRSA() const
DSA * getDSA()
SINT32 sign(const UINT8 *const in, UINT32 inlen, UINT8 *sig, UINT32 *siglen) const
Perform Signature with either DSA, RSA or ECDSA.
SINT32 getSignKey(DOMElement *&node, XERCES_CPP_NAMESPACE::DOMDocument *doc)
Gets the secret sign key as XML encode PKCS#12 struct.
UINT8 type
Definition: typedefs.hpp:1
UINT16 len
Definition: typedefs.hpp:0