2 * Copyright 2001-2005 Internet2
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 #include "internal.h"
\r
18 #include <saml/signature/SignatureProfileValidator.h>
\r
19 #include <xmltooling/signature/SignatureValidator.h>
\r
22 #include <openssl/pem.h>
\r
23 #include <xsec/enc/XSECKeyInfoResolverDefault.hpp>
\r
24 #include <xsec/enc/OpenSSL/OpenSSLCryptoX509.hpp>
\r
25 #include <xsec/enc/OpenSSL/OpenSSLCryptoKeyRSA.hpp>
\r
26 #include <xsec/enc/XSECCryptoException.hpp>
\r
27 #include <xsec/framework/XSECException.hpp>
\r
29 using namespace xmlsignature;
\r
31 class _addcert : public std::binary_function<X509Data*,XSECCryptoX509*,void> {
\r
33 void operator()(X509Data* bag, XSECCryptoX509* cert) const {
\r
34 safeBuffer& buf=cert->getDEREncodingSB();
\r
35 X509Certificate* x=X509CertificateBuilder::buildX509Certificate();
\r
36 x->setValue(buf.sbStrToXMLCh());
\r
37 bag->getX509Certificates().push_back(x);
\r
41 class SAMLSignatureTestBase : public SAMLObjectBaseTestCase {
\r
43 XSECCryptoKey* m_key;
\r
44 vector<XSECCryptoX509*> m_certs;
\r
47 SAMLObjectBaseTestCase::setUp();
\r
48 string keypath=data_path + "key.pem";
\r
49 BIO* in=BIO_new(BIO_s_file_internal());
\r
50 if (in && BIO_read_filename(in,keypath.c_str())>0) {
\r
51 EVP_PKEY* pkey=PEM_read_bio_PrivateKey(in, NULL, NULL, NULL);
\r
53 m_key=new OpenSSLCryptoKeyRSA(pkey);
\r
54 EVP_PKEY_free(pkey);
\r
57 if (in) BIO_free(in);
\r
58 TS_ASSERT(m_key!=NULL);
\r
60 string certpath=data_path + "cert.pem";
\r
61 in=BIO_new(BIO_s_file_internal());
\r
62 if (in && BIO_read_filename(in,certpath.c_str())>0) {
\r
64 while (x=PEM_read_bio_X509(in,NULL,NULL,NULL)) {
\r
65 m_certs.push_back(new OpenSSLCryptoX509(x));
\r
69 if (in) BIO_free(in);
\r
70 TS_ASSERT(m_certs.size()>0);
\r
74 SAMLObjectBaseTestCase::tearDown();
\r
76 for_each(m_certs.begin(),m_certs.end(),xmltooling::cleanup<XSECCryptoX509>());
\r