1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20 /*
21 * XSEC
22 *
23 * XSECProvider.hpp := The main interface for users wishing to gain access
24 * to signature objects
25 *
26 * $Id: XSECProvider.cpp 1833341 2018-06-11 16:25:41Z scantor $
27 *
28 */
29
30 #include <xsec/framework/XSECProvider.hpp>
31 #include <xsec/framework/XSECError.hpp>
32 #include <xsec/framework/XSECURIResolverXerces.hpp>
33
34 #include "../utils/XSECDOMUtils.hpp"
35 #include "../xenc/impl/XENCCipherImpl.hpp"
36
37 #ifdef XSEC_XKMS_ENABLED
38 # include "../xkms/impl/XKMSMessageFactoryImpl.hpp"
39 #endif
40
41 XERCES_CPP_NAMESPACE_USE
42
43 // --------------------------------------------------------------------------------
44 // Constructors/Destructors
45 // --------------------------------------------------------------------------------
46
47
XSECProvider()48 XSECProvider::XSECProvider() {
49
50 mp_URIResolver = new XSECURIResolverXerces();
51 #ifdef XSEC_XKMS_ENABLED
52 XSECnew(mp_xkmsMessageFactory, XKMSMessageFactoryImpl());
53 #endif
54 }
55
~XSECProvider()56 XSECProvider::~XSECProvider() {
57
58 if (mp_URIResolver != NULL)
59 delete mp_URIResolver;
60
61 #ifdef XSEC_XKMS_ENABLED
62 // Clean up XKMS stuff
63 delete mp_xkmsMessageFactory;
64 #endif
65 }
66
67 // --------------------------------------------------------------------------------
68 // Signature Creation/Deletion
69 // --------------------------------------------------------------------------------
70
71
newSignatureFromDOM(DOMDocument * doc,DOMNode * sigNode)72 DSIGSignature* XSECProvider::newSignatureFromDOM(DOMDocument* doc, DOMNode* sigNode) {
73
74 DSIGSignature* ret;
75
76 XSECnew(ret, DSIGSignature(doc, sigNode));
77
78 setup(ret);
79
80 return ret;
81 }
82
newSignatureFromDOM(DOMDocument * doc)83 DSIGSignature* XSECProvider::newSignatureFromDOM(DOMDocument* doc) {
84
85 DSIGSignature* ret;
86
87 DOMNode* sigNode = findDSIGNode(doc, "Signature");
88
89 if (sigNode == NULL) {
90
91 throw XSECException(XSECException::SignatureCreationError,
92 "Could not find a signature node in passed in DOM document");
93
94 }
95
96 XSECnew(ret, DSIGSignature(doc, sigNode));
97
98 setup(ret);
99
100 return ret;
101 }
102
newSignature()103 DSIGSignature* XSECProvider::newSignature() {
104
105 DSIGSignature* ret;
106
107 XSECnew(ret, DSIGSignature());
108
109 setup(ret);
110
111 return ret;
112 }
113
releaseSignature(DSIGSignature * toRelease)114 void XSECProvider::releaseSignature(DSIGSignature* toRelease) {
115 delete toRelease;
116 }
117
118 // --------------------------------------------------------------------------------
119 // Cipher Creation/Deletion
120 // --------------------------------------------------------------------------------
121
newCipher(DOMDocument * doc)122 XENCCipher* XSECProvider::newCipher(DOMDocument* doc) {
123
124 XENCCipherImpl* ret;
125
126 XSECnew(ret, XENCCipherImpl(doc));
127
128 setup(ret);
129
130 return ret;
131 }
132
releaseCipher(XENCCipher * toRelease)133 void XSECProvider::releaseCipher(XENCCipher* toRelease) {
134 delete toRelease;
135 }
136
137 #ifdef XSEC_XKMS_ENABLED
138 // --------------------------------------------------------------------------------
139 // XKMS Methods
140 // --------------------------------------------------------------------------------
141
getXKMSMessageFactory()142 XKMSMessageFactory* XSECProvider::getXKMSMessageFactory() {
143 return mp_xkmsMessageFactory;
144 }
145 #endif
146
147 // --------------------------------------------------------------------------------
148 // Environmental methods
149 // --------------------------------------------------------------------------------
150
151
setDefaultURIResolver(XSECURIResolver * resolver)152 void XSECProvider::setDefaultURIResolver(XSECURIResolver* resolver) {
153
154 if (mp_URIResolver != 0)
155 delete mp_URIResolver;
156
157 mp_URIResolver = resolver->clone();
158 }
159
160 // --------------------------------------------------------------------------------
161 // Internal functions
162 // --------------------------------------------------------------------------------
163
setup(DSIGSignature * sig)164 void XSECProvider::setup(DSIGSignature* sig) {
165
166 // Called by all Signature creation methods to set up the sig
167 sig->setURIResolver(mp_URIResolver);
168 }
169
setup(XENCCipher * cipher)170 void XSECProvider::setup(XENCCipher* cipher) {
171
172 }
173