2 * Copyright 2001-2008 Internet2
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * @file xmltooling/security/SecurityHelper.h
20 * A helper class for working with keys, certificates, etc.
23 #if !defined(__xmltooling_sechelper_h__) && !defined(XMLTOOLING_NO_XMLSEC)
24 #define __xmltooling_sechelper_h__
26 #include <xmltooling/security/XSECCryptoX509CRL.h>
27 #include <xmltooling/soap/SOAPTransport.h>
30 #include <xsec/enc/XSECCryptoKey.hpp>
31 #include <xsec/enc/XSECCryptoX509.hpp>
33 namespace xmltooling {
35 * A helper class for working with keys, certificates, etc.
37 class XMLTOOL_API SecurityHelper
41 * Loads a private key from a local file.
43 * @param pathname path to file containing key
44 * @param format optional constant identifying key encoding format
45 * @param password optional password to decrypt key
46 * @return a populated key object
48 static XSECCryptoKey* loadKeyFromFile(const char* pathname, const char* format=NULL, const char* password=NULL);
51 * Loads certificate(s) from a local file.
53 * @param certs array to populate with certificate(s)
54 * @param pathname path to file containing certificate(s)
55 * @param format optional constant identifying certificate encoding format
56 * @return size of the resulting array
58 static std::vector<XSECCryptoX509*>::size_type loadCertificatesFromFile(
59 std::vector<XSECCryptoX509*>& certs, const char* pathname, const char* format=NULL, const char* password=NULL
63 * Loads CRL(s) from a local file.
65 * @param crls array to populate with CRL(s)
66 * @param pathname path to file containing CRL(s)
67 * @param format optional constant identifying CRL encoding format
68 * @return size of the resulting array
70 static std::vector<XSECCryptoX509CRL*>::size_type loadCRLsFromFile(
71 std::vector<XSECCryptoX509CRL*>& crls, const char* pathname, const char* format=NULL
75 * Loads a private key from a URL.
77 * @param transport object to use to acquire key
78 * @param backing backing file for key (written to or read from if download fails)
79 * @param format optional constant identifying key encoding format
80 * @param password optional password to decrypt key
81 * @return a populated key object
83 static XSECCryptoKey* loadKeyFromURL(SOAPTransport& transport, const char* backing, const char* format=NULL, const char* password=NULL);
86 * Loads certificate(s) from a URL.
88 * @param certs array to populate with certificate(s)
89 * @param transport object to use to acquire certificate(s)
90 * @param backing backing file for certificate(s) (written to or read from if download fails)
91 * @param format optional constant identifying certificate encoding format
92 * @return size of the resulting array
94 static std::vector<XSECCryptoX509*>::size_type loadCertificatesFromURL(
95 std::vector<XSECCryptoX509*>& certs, SOAPTransport& transport, const char* backing, const char* format=NULL, const char* password=NULL
99 * Loads CRL(s) from a URL.
101 * @param crls array to populate with CRL(s)
102 * @param transport object to use to acquire CRL(s)
103 * @param backing backing file for CRL(s) (written to or read from if download fails)
104 * @param format optional constant identifying CRL encoding format
105 * @return size of the resulting array
107 static std::vector<XSECCryptoX509CRL*>::size_type loadCRLsFromURL(
108 std::vector<XSECCryptoX509CRL*>& crls, SOAPTransport& transport, const char* backing, const char* format=NULL
112 * Compares two keys for equality.
114 * @param key1 first key to compare
115 * @param key2 second key to compare
116 * @return true iff the keys match
118 static bool matches(const XSECCryptoKey* key1, const XSECCryptoKey* key2);
122 #endif /* __xmltooling_sechelper_h__ */