Produced by Araxis Merge on 9/25/2018 2:13:04 PM Central Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
# | Location | File | Last Modified |
---|---|---|---|
1 | build 3.zip\build 3\MHLTH_YS_137_Source\JavaScript\resources\javaJDF-1.8.0\src\com\sun\org\apache\xml\internal\security\keys\keyresolver\implementations | KeyInfoReferenceResolver.java | Mon Jan 22 14:46:50 2018 UTC |
2 | build 3.zip\build 3\MHLTH_YS_137_Source\JavaScript\resources\javaJDF-1.8.0\src\com\sun\org\apache\xml\internal\security\keys\keyresolver\implementations | KeyInfoReferenceResolver.java | Wed Sep 12 16:37:53 2018 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 2 | 578 |
Changed | 1 | 2 |
Inserted | 0 | 0 |
Removed | 0 | 0 |
Whitespace | |
---|---|
Character case | Differences in character case are significant |
Line endings | Differences in line endings (CR and LF characters) are ignored |
CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
1 | /* | |
2 | * reserve d comment block | |
3 | * DO NOT REMOVE OR ALTER! | |
4 | */ | |
5 | package co m.sun.org. apache.xml .internal. security.k eys.keyres olver.impl ementation s; | |
6 | ||
7 | import jav a.io.ByteA rrayInputS tream; | |
8 | import jav a.io.IOExc eption; | |
9 | import jav a.security .PrivateKe y; | |
10 | import jav a.security .PublicKey ; | |
11 | import jav a.security .cert.X509 Certificat e; | |
12 | ||
13 | import jav ax.crypto. SecretKey; | |
14 | import jav ax.xml.XML Constants; | |
15 | import jav ax.xml.nam espace.QNa me; | |
16 | import jav ax.xml.par sers.Docum entBuilder ; | |
17 | import jav ax.xml.par sers.Docum entBuilder Factory; | |
18 | import jav ax.xml.par sers.Parse rConfigura tionExcept ion; | |
19 | ||
20 | import com .sun.org.a pache.xml. internal.s ecurity.c1 4n.Canonic alizationE xception; | |
21 | import com .sun.org.a pache.xml. internal.s ecurity.ex ceptions.X MLSecurity Exception; | |
22 | import com .sun.org.a pache.xml. internal.s ecurity.ke ys.KeyInfo ; | |
23 | import com .sun.org.a pache.xml. internal.s ecurity.ke ys.content .KeyInfoRe ference; | |
24 | import com .sun.org.a pache.xml. internal.s ecurity.ke ys.keyreso lver.KeyRe solverExce ption; | |
25 | import com .sun.org.a pache.xml. internal.s ecurity.ke ys.keyreso lver.KeyRe solverSpi; | |
26 | import com .sun.org.a pache.xml. internal.s ecurity.ke ys.storage .StorageRe solver; | |
27 | import com .sun.org.a pache.xml. internal.s ecurity.si gnature.XM LSignature Input; | |
28 | import com .sun.org.a pache.xml. internal.s ecurity.ut ils.Consta nts; | |
29 | import com .sun.org.a pache.xml. internal.s ecurity.ut ils.XMLUti ls; | |
30 | import com .sun.org.a pache.xml. internal.s ecurity.ut ils.resolv er.Resourc eResolver; | |
31 | import org .w3c.dom.A ttr; | |
32 | import org .w3c.dom.D ocument; | |
33 | import org .w3c.dom.E lement; | |
34 | import org .xml.sax.S AXExceptio n; | |
35 | ||
36 | /** | |
37 | * KeyReso lverSpi im plementati on which r esolves pu blic keys, private k eys, PW keys, and X.509 cert ificates f rom a | |
38 | * <code>d sig11:KeyI nfoReferen ce</code> element. | |
39 | * | |
40 | * @author Brent Put man (putma nb@georget own.edu) | |
41 | */ | |
42 | public cla ss KeyInfo ReferenceR esolver ex tends KeyR esolverSpi { | |
43 | ||
44 | /** {@ link org.a pache.comm ons.loggin g} logging facility */ | |
45 | privat e static j ava.util.l ogging.Log ger log = | |
46 | ja va.util.lo gging.Logg er.getLogg er(KeyInfo ReferenceR esolver.cl ass.getNam e()); | |
47 | ||
48 | /** {@ inheritDoc }. */ | |
49 | public boolean e ngineCanRe solve(Elem ent elemen t, String baseURI, S torageReso lver stora ge) { | |
50 | re turn XMLUt ils.elemen tIsInSigna ture11Spac e(element, Constants ._TAG_KEYI NFOREFEREN CE); | |
51 | } | |
52 | ||
53 | /** {@ inheritDoc }. */ | |
54 | public PublicKey engineLoo kupAndReso lvePublicK ey(Element element, String bas eURI, Stor ageResolve r storage) | |
55 | th rows KeyRe solverExce ption { | |
56 | ||
57 | if (log.isLo ggable(jav a.util.log ging.Level .FINE)) { | |
58 | log.log( java.util. logging.Le vel.FINE, "Can I res olve " + e lement.get TagName()) ; | |
59 | } | |
60 | ||
61 | if (!engineC anResolve( element, b aseURI, st orage)) { | |
62 | return n ull; | |
63 | } | |
64 | ||
65 | tr y { | |
66 | KeyInfo referent = resolveRe ferentKeyI nfo(elemen t, baseURI , storage) ; | |
67 | if (refe rent != nu ll) { | |
68 | retu rn referen t.getPubli cKey(); | |
69 | } | |
70 | } catch (XML SecurityEx ception e) { | |
71 | if (log. isLoggable (java.util .logging.L evel.FINE) ) { | |
72 | log. log(java.u til.loggin g.Level.FI NE, "XMLSe curityExce ption", e) ; | |
73 | } | |
74 | } | |
75 | ||
76 | re turn null; | |
77 | } | |
78 | ||
79 | /** {@ inheritDoc }. */ | |
80 | public X509Certi ficate eng ineLookupR esolveX509 Certificat e(Element element, S tring base URI, Stora geResolver storage) | |
81 | th rows KeyRe solverExce ption { | |
82 | ||
83 | if (log.isLo ggable(jav a.util.log ging.Level .FINE)) { | |
84 | log.log( java.util. logging.Le vel.FINE, "Can I res olve " + e lement.get TagName()) ; | |
85 | } | |
86 | ||
87 | if (!engineC anResolve( element, b aseURI, st orage)) { | |
88 | return n ull; | |
89 | } | |
90 | ||
91 | tr y { | |
92 | KeyInfo referent = resolveRe ferentKeyI nfo(elemen t, baseURI , storage) ; | |
93 | if (refe rent != nu ll) { | |
94 | retu rn referen t.getX509C ertificate (); | |
95 | } | |
96 | } catch (XML SecurityEx ception e) { | |
97 | if (log. isLoggable (java.util .logging.L evel.FINE) ) { | |
98 | log. log(java.u til.loggin g.Level.FI NE, "XMLSe curityExce ption", e) ; | |
99 | } | |
100 | } | |
101 | ||
102 | re turn null; | |
103 | } | |
104 | ||
105 | /** {@ inheritDoc }. */ | |
106 | public SecretKey engineLoo kupAndReso lveSecretK ey(Element element, String bas eURI, Stor ageResolve r storage) | |
107 | th rows KeyRe solverExce ption { | |
108 | ||
109 | if (log.isLo ggable(jav a.util.log ging.Level .FINE)) { | |
110 | log.log( java.util. logging.Le vel.FINE, "Can I res olve " + e lement.get TagName()) ; | |
111 | } | |
112 | ||
113 | if (!engineC anResolve( element, b aseURI, st orage)) { | |
114 | return n ull; | |
115 | } | |
116 | ||
117 | tr y { | |
118 | KeyInfo referent = resolveRe ferentKeyI nfo(elemen t, baseURI , storage) ; | |
119 | if (refe rent != nu ll) { | |
120 | retu rn referen t.getSecre tKey(); | |
121 | } | |
122 | } catch (XML SecurityEx ception e) { | |
123 | if (log. isLoggable (java.util .logging.L evel.FINE) ) { | |
124 | log. log(java.u til.loggin g.Level.FI NE, "XMLSe curityExce ption", e) ; | |
125 | } | |
126 | } | |
127 | ||
128 | re turn null; | |
129 | } | |
130 | ||
131 | /** {@ inheritDoc }. */ | |
132 | public PrivateKe y engineLo okupAndRes olvePrivat eKey(Eleme nt element , String b aseURI, St orageResol ver storag e) | |
133 | th rows KeyRe solverExce ption { | |
134 | ||
135 | if (log.isLo ggable(jav a.util.log ging.Level .FINE)) { | |
136 | log.log( java.util. logging.Le vel.FINE, "Can I res olve " + e lement.get TagName()) ; | |
137 | } | |
138 | ||
139 | if (!engineC anResolve( element, b aseURI, st orage)) { | |
140 | return n ull; | |
141 | } | |
142 | ||
143 | tr y { | |
144 | KeyInfo referent = resolveRe ferentKeyI nfo(elemen t, baseURI , storage) ; | |
145 | if (refe rent != nu ll) { | |
146 | retu rn referen t.getPriva teKey(); | |
147 | } | |
148 | } catch (XML SecurityEx ception e) { | |
149 | if (log. isLoggable (java.util .logging.L evel.FINE) ) { | |
150 | log. log(java.u til.loggin g.Level.FI NE, "XMLSe curityExce ption", e) ; | |
151 | } | |
152 | } | |
153 | ||
154 | re turn null; | |
155 | } | |
156 | ||
157 | /** | |
158 | * Res olve the K eyInfoRefe rence Elem ent's URI attribute into a Key Info insta nce. | |
159 | * | |
160 | * @pa ram elemen t | |
161 | * @pa ram baseUR I | |
162 | * @pa ram storag e | |
163 | * @re turn the K eyInfo whi ch is refe rred to by this KeyI nfoReferen ce, or nul l if can n ot be reso lved | |
164 | * @th rows XMLSe curityExce ption | |
165 | */ | |
166 | privat e KeyInfo resolveRef erentKeyIn fo(Element element, String bas eURI, Stor ageResolve r storage) throws XM LSecurityE xception { | |
167 | Ke yInfoRefer ence refer ence = new KeyInfoRe ference(el ement, bas eURI); | |
168 | At tr uriAttr = referen ce.getURIA ttr(); | |
169 | ||
170 | XM LSignature Input reso urce = res olveInput( uriAttr, b aseURI, se cureValida tion); | |
171 | ||
172 | El ement refe rentElemen t = null; | |
173 | tr y { | |
174 | referent Element = obtainRefe renceEleme nt(resourc e); | |
175 | } catch (Exc eption e) { | |
176 | if (log. isLoggable (java.util .logging.L evel.FINE) ) { | |
177 | log. log(java.u til.loggin g.Level.FI NE, "XMLSe curityExce ption", e) ; | |
178 | } | |
179 | return n ull; | |
180 | } | |
181 | ||
182 | if (referent Element == null) { | |
183 | log.log( java.util. logging.Le vel.FINE, "De-refere nce of Key InfoRefere nce URI re turned nul l: " + uri Attr.getVa lue()); | |
184 | return n ull; | |
185 | } | |
186 | ||
187 | va lidateRefe rence(refe rentElemen t); | |
188 | ||
189 | Ke yInfo refe rent = new KeyInfo(r eferentEle ment, base URI); | |
190 | re ferent.add StorageRes olver(stor age); | |
191 | re turn refer ent; | |
192 | } | |
193 | ||
194 | /** | |
195 | * Val idate the Element re ferred to by the Key InfoRefere nce. | |
196 | * | |
197 | * @pa ram refere ntElement | |
198 | * | |
199 | * @th rows XMLSe curityExce ption | |
200 | */ | |
201 | privat e void val idateRefer ence(Eleme nt referen tElement) throws XML SecurityEx ception { | |
202 | if (!XMLUtil s.elementI sInSignatu reSpace(re ferentElem ent, Const ants._TAG_ KEYINFO)) { | |
203 | Object e xArgs[] = { new QNam e(referent Element.ge tNamespace URI(), ref erentEleme nt.getLoca lName()) } ; | |
204 | throw ne w XMLSecur ityExcepti on("KeyInf oReference Resolver.I nvalidRefe rentElemen t.WrongTyp e", exArgs ); | |
205 | } | |
206 | ||
207 | Ke yInfo refe rent = new KeyInfo(r eferentEle ment, ""); | |
208 | if (referent .containsK eyInfoRefe rence()) { | |
209 | if (secu reValidati on) { | |
210 | thro w new XMLS ecurityExc eption("Ke yInfoRefer enceResolv er.Invalid ReferentEl ement.Refe renceWithS ecure"); | |
211 | } else { | |
212 | // D on't suppo rt chains of referen ces at thi s time. If do suppor t in the f uture, thi s is where the code | |
213 | // w ould go to validate that don't have a cy cle, resul ting in an infinite loop. This may be un realistic | |
214 | // t o implemen t, and/or very expen sive given remote UR I referenc es. | |
215 | thro w new XMLS ecurityExc eption("Ke yInfoRefer enceResolv er.Invalid ReferentEl ement.Refe renceWitho utSecure") ; | |
216 | } | |
217 | } | |
218 | ||
219 | } | |
220 | ||
221 | /** | |
222 | * Res olve the X ML signatu re input r epresented by the sp ecified UR I. | |
223 | * | |
224 | * @pa ram uri | |
225 | * @pa ram baseUR I | |
226 | * @pa ram secure Validation | |
227 | * @re turn | |
228 | * @th rows XMLSe curityExce ption | |
229 | */ | |
230 | privat e XMLSigna tureInput resolveInp ut(Attr ur i, String baseURI, b oolean sec ureValidat ion) | |
231 | th rows XMLSe curityExce ption { | |
232 | Re sourceReso lver resRe s = Resour ceResolver .getInstan ce(uri, ba seURI, sec ureValidat ion); | |
233 | XM LSignature Input reso urce = res Res.resolv e(uri, bas eURI, secu reValidati on); | |
234 | re turn resou rce; | |
235 | } | |
236 | ||
237 | /** | |
238 | * Res olve the E lement eff ectively r epresented by the XM L signatur e input so urce. | |
239 | * | |
240 | * @pa ram resour ce | |
241 | * @re turn | |
242 | * @th rows Canon icalizatio nException | |
243 | * @th rows Parse rConfigura tionExcept ion | |
244 | * @th rows IOExc eption | |
245 | * @th rows SAXEx ception | |
246 | * @th rows KeyRe solverExce ption | |
247 | */ | |
248 | privat e Element obtainRefe renceEleme nt(XMLSign atureInput resource) | |
249 | th rows Canon icalizatio nException , ParserCo nfiguratio nException , | |
250 | IO Exception, SAXExcept ion, KeyRe solverExce ption { | |
251 | ||
252 | El ement e; | |
253 | if (resource .isElement ()){ | |
254 | e = (Ele ment) reso urce.getSu bNode(); | |
255 | } else if (r esource.is NodeSet()) { | |
256 | log.log( java.util. logging.Le vel.FINE, "De-refere nce of Key InfoRefere nce return ed an unsu pported No deSet"); | |
257 | return n ull; | |
258 | } else { | |
259 | // Retri eved resou rce is a b yte stream | |
260 | byte inp utBytes[] = resource .getBytes( ); | |
261 | e = getD ocFromByte s(inputByt es); | |
262 | } | |
263 | re turn e; | |
264 | } | |
265 | ||
266 | /** | |
267 | * Par ses a byte array and returns t he parsed Element. | |
268 | * | |
269 | * @pa ram bytes | |
270 | * @re turn the D ocument El ement afte r parsing bytes | |
271 | * @th rows KeyRe solverExce ption if s omething g oes wrong | |
272 | */ | |
273 | privat e Element getDocFrom Bytes(byte [] bytes) throws Key ResolverEx ception { | |
274 | tr y { | |
275 | Document BuilderFac tory dbf = DocumentB uilderFact ory.newIns tance(); | |
276 | dbf.setN amespaceAw are(true); | |
277 | dbf.setF eature(XML Constants. FEATURE_SE CURE_PROCE SSING, Boo lean.TRUE) ; | |
278 | Document Builder db = dbf.new DocumentBu ilder(); | |
279 | Document doc = db. parse(new ByteArrayI nputStream (bytes)); | |
280 | return d oc.getDocu mentElemen t(); | |
281 | } catch (SAX Exception ex) { | |
282 | throw ne w KeyResol verExcepti on("empty" , ex); | |
283 | } catch (IOE xception e x) { | |
284 | throw ne w KeyResol verExcepti on("empty" , ex); | |
285 | } catch (Par serConfigu rationExce ption ex) { | |
286 | throw ne w KeyResol verExcepti on("empty" , ex); | |
287 | } | |
288 | } | |
289 | ||
290 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.