PageRenderTime 46ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/projects/jruby-1.7.3/src/org/jruby/ext/openssl/x509store/StoreContext.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Java | 1401 lines | 1052 code | 129 blank | 220 comment | 411 complexity | 6670533f3b704c6289b6145c34b335e9 MD5 | raw file
  1. /***** BEGIN LICENSE BLOCK *****
  2. * Version: EPL 1.0/GPL 2.0/LGPL 2.1
  3. *
  4. * The contents of this file are subject to the Common Public
  5. * License Version 1.0 (the "License"); you may not use this file
  6. * except in compliance with the License. You may obtain a copy of
  7. * the License at http://www.eclipse.org/legal/cpl-v10.html
  8. *
  9. * Software distributed under the License is distributed on an "AS
  10. * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  11. * implied. See the License for the specific language governing
  12. * rights and limitations under the License.
  13. *
  14. * Copyright (C) 2006 Ola Bini <ola@ologix.com>
  15. *
  16. * Alternatively, the contents of this file may be used under the terms of
  17. * either of the GNU General Public License Version 2 or later (the "GPL"),
  18. * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  19. * in which case the provisions of the GPL or the LGPL are applicable instead
  20. * of those above. If you wish to allow use of your version of this file only
  21. * under the terms of either the GPL or the LGPL, and not to allow others to
  22. * use your version of this file under the terms of the EPL, indicate your
  23. * decision by deleting the provisions above and replace them with the notice
  24. * and other provisions required by the GPL or the LGPL. If you do not delete
  25. * the provisions above, a recipient may use your version of this file under
  26. * the terms of any one of the EPL, the GPL or the LGPL.
  27. ***** END LICENSE BLOCK *****/
  28. package org.jruby.ext.openssl.x509store;
  29. import java.security.PublicKey;
  30. import java.security.cert.X509CRL;
  31. import java.security.cert.X509Certificate;
  32. import java.security.cert.X509Extension;
  33. import java.util.Calendar;
  34. import java.util.Collection;
  35. import java.util.Date;
  36. import java.util.ArrayList;
  37. import java.util.List;
  38. import java.util.Set;
  39. import java.util.HashSet;
  40. import org.bouncycastle.asn1.ASN1InputStream;
  41. import org.bouncycastle.asn1.DLSequence;
  42. import org.bouncycastle.asn1.ASN1Integer;
  43. import org.bouncycastle.asn1.ASN1Sequence;
  44. /**
  45. * c: X509_STORE_CTX
  46. *
  47. * @author <a href="mailto:ola.bini@ki.se">Ola Bini</a>
  48. */
  49. public class StoreContext {
  50. public Store ctx;
  51. public int currentMethod;
  52. public X509AuxCertificate certificate;
  53. public List<X509AuxCertificate> untrusted;
  54. public List<X509CRL> crls;
  55. public VerifyParameter param;
  56. public List<X509AuxCertificate> otherContext;
  57. public static interface CheckPolicyFunction extends Function1 {
  58. public static final CheckPolicyFunction EMPTY = new CheckPolicyFunction(){
  59. public int call(Object arg0) {
  60. return -1;
  61. }
  62. };
  63. }
  64. public Store.VerifyFunction verify;
  65. public Store.VerifyCallbackFunction verifyCallback;
  66. public Store.GetIssuerFunction getIssuer;
  67. public Store.CheckIssuedFunction checkIssued;
  68. public Store.CheckRevocationFunction checkRevocation;
  69. public Store.GetCRLFunction getCRL;
  70. public Store.CheckCRLFunction checkCRL;
  71. public Store.CertificateCRLFunction certificateCRL;
  72. public CheckPolicyFunction checkPolicy;
  73. public Store.CleanupFunction cleanup;
  74. public boolean isValid;
  75. public int lastUntrusted;
  76. public List<X509AuxCertificate> chain; //List<X509AuxCertificate>
  77. public PolicyTree tree;
  78. public int explicitPolicy;
  79. public int errorDepth;
  80. public int error;
  81. public X509AuxCertificate currentCertificate;
  82. public X509AuxCertificate currentIssuer;
  83. public java.security.cert.CRL currentCRL;
  84. public List<Object> extraData;
  85. /**
  86. * c: X509_STORE_CTX_set_depth
  87. */
  88. public void setDepth(int depth) {
  89. param.setDepth(depth);
  90. }
  91. /**
  92. * c: X509_STORE_CTX_set_app_data
  93. */
  94. public void setApplicationData(Object data) {
  95. setExtraData(0,data);
  96. }
  97. /**
  98. * c: X509_STORE_CTX_get_app_data
  99. */
  100. public Object getApplicationData() {
  101. return getExtraData(0);
  102. }
  103. /**
  104. * c: X509_STORE_CTX_get1_issuer
  105. */
  106. public int getFirstIssuer(X509AuxCertificate[] issuer, X509AuxCertificate x) throws Exception {
  107. Name xn = new Name(x.getIssuerX500Principal());
  108. X509Object[] s_obj = new X509Object[1];
  109. int ok = ctx == null ? 0 : getBySubject(X509Utils.X509_LU_X509,xn,s_obj);
  110. if(ok != X509Utils.X509_LU_X509) {
  111. if(ok == X509Utils.X509_LU_RETRY) {
  112. X509Error.addError(X509Utils.X509_R_SHOULD_RETRY);
  113. return -1;
  114. } else if (ok != X509Utils.X509_LU_FAIL) {
  115. return -1;
  116. }
  117. return 0;
  118. }
  119. X509Object obj = s_obj[0];
  120. if(this.checkIssued.call(this,x,((Certificate)obj).x509) != 0) {
  121. issuer[0] = ((Certificate)obj).x509;
  122. return 1;
  123. }
  124. int idx = X509Object.indexBySubject(ctx.objs,X509Utils.X509_LU_X509, xn);
  125. if(idx == -1) {
  126. return 0;
  127. }
  128. /* Look through all matching certificates for a suitable issuer */
  129. for(int i = idx; i < ctx.objs.size(); i++) {
  130. X509Object pobj = ctx.objs.get(i);
  131. if(pobj.type() != X509Utils.X509_LU_X509) {
  132. return 0;
  133. }
  134. if(!xn.isEqual((((Certificate)pobj).x509).getSubjectX500Principal())) {
  135. return 0;
  136. }
  137. if(this.checkIssued.call(this,x,((Certificate)pobj).x509) != 0) {
  138. issuer[0] = ((Certificate)pobj).x509;
  139. return 1;
  140. }
  141. }
  142. return 0;
  143. }
  144. public static List<X509AuxCertificate> ensureAux(Collection<X509Certificate> inp) {
  145. if (inp == null) {
  146. return null;
  147. }
  148. List<X509AuxCertificate> out = new ArrayList<X509AuxCertificate>();
  149. for(X509Certificate o : inp) {
  150. out.add(ensureAux(o));
  151. }
  152. return out;
  153. }
  154. public static List<X509AuxCertificate> ensureAux(X509Certificate[] inp) {
  155. if (inp == null) {
  156. return null;
  157. }
  158. List<X509AuxCertificate> o = new ArrayList<X509AuxCertificate>();
  159. for(X509Certificate c : inp) {
  160. o.add(ensureAux(c));
  161. }
  162. return o;
  163. }
  164. public static X509AuxCertificate ensureAux(X509Certificate i) {
  165. if (i == null) {
  166. return null;
  167. }
  168. if(i instanceof X509AuxCertificate) {
  169. return (X509AuxCertificate)i;
  170. } else {
  171. return new X509AuxCertificate(i);
  172. }
  173. }
  174. /**
  175. * c: X509_STORE_CTX_init
  176. */
  177. public int init(Store store, X509AuxCertificate x509, List<X509AuxCertificate> chain) {
  178. int ret = 1;
  179. this.ctx=store;
  180. this.currentMethod=0;
  181. this.certificate=x509;
  182. this.untrusted=chain;
  183. this.crls = null;
  184. this.lastUntrusted=0;
  185. this.otherContext = null;
  186. this.isValid=false;
  187. this.chain = null;
  188. this.error=0;
  189. this.explicitPolicy=0;
  190. this.errorDepth=0;
  191. this.currentCertificate=null;
  192. this.currentIssuer=null;
  193. this.tree = null;
  194. this.param = new VerifyParameter();
  195. if(store != null) {
  196. ret = param.inherit(store.param);
  197. } else {
  198. param.flags |= X509Utils.X509_VP_FLAG_DEFAULT | X509Utils.X509_VP_FLAG_ONCE;
  199. }
  200. if(store != null) {
  201. verifyCallback = store.verifyCallback;
  202. cleanup = store.cleanup;
  203. } else {
  204. cleanup = Store.CleanupFunction.EMPTY;
  205. }
  206. if(ret != 0) {
  207. ret = param.inherit(VerifyParameter.lookup("default"));
  208. }
  209. if(ret == 0) {
  210. X509Error.addError(X509Utils.ERR_R_MALLOC_FAILURE);
  211. return 0;
  212. }
  213. if(store != null && store.checkIssued != null && store.checkIssued != Store.CheckIssuedFunction.EMPTY) {
  214. this.checkIssued = store.checkIssued;
  215. } else {
  216. this.checkIssued = defaultCheckIssued;
  217. }
  218. if(store != null && store.getIssuer != null && store.getIssuer != Store.GetIssuerFunction.EMPTY) {
  219. this.getIssuer = store.getIssuer;
  220. } else {
  221. this.getIssuer = new Store.GetIssuerFunction() {
  222. public int call(Object arg1, Object arg2, Object arg3) throws Exception {
  223. return ((StoreContext)arg2).getFirstIssuer((X509AuxCertificate[])arg1,(X509AuxCertificate)arg3);
  224. }
  225. };
  226. }
  227. if(store != null && store.verifyCallback != null && store.verifyCallback != Store.VerifyCallbackFunction.EMPTY) {
  228. this.verifyCallback = store.verifyCallback;
  229. } else {
  230. this.verifyCallback = NullCallback;
  231. }
  232. if(store != null && store.verify != null && store.verify != Store.VerifyFunction.EMPTY) {
  233. this.verify = store.verify;
  234. } else {
  235. this.verify = internalVerify;
  236. }
  237. if(store != null && store.checkRevocation != null && store.checkRevocation != Store.CheckRevocationFunction.EMPTY) {
  238. this.checkRevocation = store.checkRevocation;
  239. } else {
  240. this.checkRevocation = defaultCheckRevocation;
  241. }
  242. if(store != null && store.getCRL != null && store.getCRL != Store.GetCRLFunction.EMPTY) {
  243. this.getCRL = store.getCRL;
  244. } else {
  245. this.getCRL = defaultGetCRL;
  246. }
  247. if(store != null && store.checkCRL != null && store.checkCRL != Store.CheckCRLFunction.EMPTY) {
  248. this.checkCRL = store.checkCRL;
  249. } else {
  250. this.checkCRL = defaultCheckCRL;
  251. }
  252. if(store != null && store.certificateCRL != null && store.certificateCRL != Store.CertificateCRLFunction.EMPTY) {
  253. this.certificateCRL = store.certificateCRL;
  254. } else {
  255. this.certificateCRL = defaultCertificateCRL;
  256. }
  257. this.checkPolicy = defaultCheckPolicy;
  258. this.extraData = new ArrayList<Object>();
  259. this.extraData.add(null);this.extraData.add(null);this.extraData.add(null);
  260. this.extraData.add(null);this.extraData.add(null);this.extraData.add(null);
  261. return 1;
  262. }
  263. /**
  264. * c: X509_STORE_CTX_trusted_stack
  265. */
  266. public void trustedStack(List<X509AuxCertificate> sk) {
  267. otherContext = sk;
  268. getIssuer = getIssuerStack;
  269. }
  270. /**
  271. * c: X509_STORE_CTX_cleanup
  272. */
  273. public void cleanup() throws Exception {
  274. if(cleanup != null && cleanup != Store.CleanupFunction.EMPTY) {
  275. cleanup.call(this);
  276. }
  277. param = null;
  278. tree = null;
  279. chain = null;
  280. extraData = null;
  281. }
  282. /**
  283. * c: find_issuer
  284. */
  285. public X509AuxCertificate findIssuer(List<X509AuxCertificate> sk, X509AuxCertificate x) throws Exception {
  286. for(X509AuxCertificate issuer : sk) {
  287. if(checkIssued.call(this,x,issuer) != 0) {
  288. return issuer;
  289. }
  290. }
  291. return null;
  292. }
  293. /**
  294. * c: X509_STORE_CTX_set_ex_data
  295. */
  296. public int setExtraData(int idx,Object data) {
  297. extraData.set(idx,data);
  298. return 1;
  299. }
  300. /**
  301. * c: X509_STORE_CTX_get_ex_data
  302. */
  303. public Object getExtraData(int idx) {
  304. return extraData.get(idx);
  305. }
  306. /**
  307. * c: X509_STORE_CTX_get_error
  308. */
  309. public int getError() {
  310. return error;
  311. }
  312. /**
  313. * c: X509_STORE_CTX_set_error
  314. */
  315. public void setError(int s) {
  316. this.error = s;
  317. }
  318. /**
  319. * c: X509_STORE_CTX_get_error_depth
  320. */
  321. public int getErrorDepth() {
  322. return errorDepth;
  323. }
  324. /**
  325. * c: X509_STORE_CTX_get_current_cert
  326. */
  327. public X509AuxCertificate getCurrentCertificate() {
  328. return currentCertificate;
  329. }
  330. /**
  331. * c: X509_STORE_CTX_get_chain
  332. */
  333. public List<X509AuxCertificate> getChain() {
  334. return chain;
  335. }
  336. /**
  337. * c: X509_STORE_CTX_get1_chain
  338. */
  339. public List<X509AuxCertificate> getFirstChain() {
  340. if(null == chain) {
  341. return null;
  342. }
  343. return new ArrayList<X509AuxCertificate>(chain);
  344. }
  345. /**
  346. * c: X509_STORE_CTX_set_cert
  347. */
  348. public void setCertificate(X509AuxCertificate x) {
  349. this.certificate = x;
  350. }
  351. public void setCertificate(X509Certificate x) {
  352. this.certificate = ensureAux(x);
  353. }
  354. /**
  355. * c: X509_STORE_CTX_set_chain
  356. */
  357. public void setChain(List<X509Certificate> sk) {
  358. this.untrusted = ensureAux(sk);
  359. }
  360. public void setChain(X509Certificate[] sk) {
  361. this.untrusted = ensureAux(sk);
  362. }
  363. /**
  364. * c: X509_STORE_CTX_set0_crls
  365. */
  366. public void setCRLs(List<X509CRL> sk) {
  367. this.crls = sk;
  368. }
  369. /**
  370. * c: X509_STORE_CTX_set_purpose
  371. */
  372. public int setPurpose(int purpose) {
  373. return purposeInherit(0,purpose,0);
  374. }
  375. /**
  376. * c: X509_STORE_CTX_set_trust
  377. */
  378. public int setTrust(int trust) {
  379. return purposeInherit(0,0,trust);
  380. }
  381. private void resetSettingsToWithoutStore() {
  382. ctx = null;
  383. this.param = new VerifyParameter();
  384. this.param.flags |= X509Utils.X509_VP_FLAG_DEFAULT | X509Utils.X509_VP_FLAG_ONCE;
  385. this.param.inherit(VerifyParameter.lookup("default"));
  386. this.cleanup = Store.CleanupFunction.EMPTY;
  387. this.checkIssued = defaultCheckIssued;
  388. this.getIssuer = new Store.GetIssuerFunction() {
  389. public int call(Object arg1, Object arg2, Object arg3) throws Exception {
  390. return ((StoreContext)arg2).getFirstIssuer((X509AuxCertificate[])arg1,(X509AuxCertificate)arg3);
  391. }
  392. };
  393. this.verifyCallback = NullCallback;
  394. this.verify = internalVerify;
  395. this.checkRevocation = defaultCheckRevocation;
  396. this.getCRL = defaultGetCRL;
  397. this.checkCRL = defaultCheckCRL;
  398. this.certificateCRL = defaultCertificateCRL;
  399. }
  400. /**
  401. * c: SSL_CTX_load_verify_locations
  402. */
  403. public int loadVerifyLocations(String CAfile, String CApath) {
  404. boolean reset = false;
  405. try {
  406. if(ctx == null) {
  407. reset = true;
  408. ctx = new Store();
  409. this.param.inherit(ctx.param);
  410. param.inherit(VerifyParameter.lookup("default"));
  411. this.cleanup = ctx.cleanup;
  412. if(ctx.checkIssued != null && ctx.checkIssued != Store.CheckIssuedFunction.EMPTY) {
  413. this.checkIssued = ctx.checkIssued;
  414. }
  415. if(ctx.getIssuer != null && ctx.getIssuer != Store.GetIssuerFunction.EMPTY) {
  416. this.getIssuer = ctx.getIssuer;
  417. }
  418. if(ctx.verifyCallback != null && ctx.verifyCallback != Store.VerifyCallbackFunction.EMPTY) {
  419. this.verifyCallback = ctx.verifyCallback;
  420. }
  421. if(ctx.verify != null && ctx.verify != Store.VerifyFunction.EMPTY) {
  422. this.verify = ctx.verify;
  423. }
  424. if(ctx.checkRevocation != null && ctx.checkRevocation != Store.CheckRevocationFunction.EMPTY) {
  425. this.checkRevocation = ctx.checkRevocation;
  426. }
  427. if(ctx.getCRL != null && ctx.getCRL != Store.GetCRLFunction.EMPTY) {
  428. this.getCRL = ctx.getCRL;
  429. }
  430. if(ctx.checkCRL != null && ctx.checkCRL != Store.CheckCRLFunction.EMPTY) {
  431. this.checkCRL = ctx.checkCRL;
  432. }
  433. if(ctx.certificateCRL != null && ctx.certificateCRL != Store.CertificateCRLFunction.EMPTY) {
  434. this.certificateCRL = ctx.certificateCRL;
  435. }
  436. }
  437. int ret = ctx.loadLocations(CAfile, CApath);
  438. if(ret == 0 && reset) resetSettingsToWithoutStore();
  439. return ret;
  440. } catch(Exception e) {
  441. if(reset) {
  442. resetSettingsToWithoutStore();
  443. }
  444. return 0;
  445. }
  446. }
  447. /**
  448. * c: X509_STORE_CTX_purpose_inherit
  449. */
  450. public int purposeInherit(int defaultPurpose,int purpose, int trust) {
  451. int idx;
  452. if(purpose == 0) {
  453. purpose = defaultPurpose;
  454. }
  455. if(purpose != 0) {
  456. idx = Purpose.getByID(purpose);
  457. if(idx == -1) {
  458. X509Error.addError(X509Utils.X509_R_UNKNOWN_PURPOSE_ID);
  459. return 0;
  460. }
  461. Purpose ptmp = Purpose.getFirst(idx);
  462. if(ptmp.trust == X509Utils.X509_TRUST_DEFAULT) {
  463. idx = Purpose.getByID(defaultPurpose);
  464. if(idx == -1) {
  465. X509Error.addError(X509Utils.X509_R_UNKNOWN_PURPOSE_ID);
  466. return 0;
  467. }
  468. ptmp = Purpose.getFirst(idx);
  469. }
  470. if(trust == 0) {
  471. trust = ptmp.trust;
  472. }
  473. }
  474. if(trust != 0) {
  475. idx = Trust.getByID(trust);
  476. if(idx == -1) {
  477. X509Error.addError(X509Utils.X509_R_UNKNOWN_TRUST_ID);
  478. return 0;
  479. }
  480. }
  481. if(purpose != 0 && param.purpose == 0) {
  482. param.purpose = purpose;
  483. }
  484. if(trust != 0 && param.trust == 0) {
  485. param.trust = trust;
  486. }
  487. return 1;
  488. }
  489. /**
  490. * c: X509_STORE_CTX_set_flags
  491. */
  492. public void setFlags(long flags) {
  493. param.setFlags(flags);
  494. }
  495. /**
  496. * c: X509_STORE_CTX_set_time
  497. */
  498. public void setTime(long flags,Date t) {
  499. param.setTime(t);
  500. }
  501. /**
  502. * c: X509_STORE_CTX_set_verify_cb
  503. */
  504. public void setVerifyCallback(Store.VerifyCallbackFunction verifyCallback) {
  505. this.verifyCallback = verifyCallback;
  506. }
  507. /**
  508. * c: X509_STORE_CTX_get0_policy_tree
  509. */
  510. PolicyTree getPolicyTree() {
  511. return tree;
  512. }
  513. /**
  514. * c: X509_STORE_CTX_get_explicit_policy
  515. */
  516. public int getExplicitPolicy() {
  517. return explicitPolicy;
  518. }
  519. /**
  520. * c: X509_STORE_CTX_get0_param
  521. */
  522. public VerifyParameter getParam() {
  523. return param;
  524. }
  525. /**
  526. * c: X509_STORE_CTX_set0_param
  527. */
  528. public void setParam(VerifyParameter param) {
  529. this.param = param;
  530. }
  531. /**
  532. * c: X509_STORE_CTX_set_default
  533. */
  534. public int setDefault(String name) {
  535. VerifyParameter p = VerifyParameter.lookup(name);
  536. if(p == null) {
  537. return 0;
  538. }
  539. return param.inherit(p);
  540. }
  541. /**
  542. * c: X509_STORE_get_by_subject (it gets X509_STORE_CTX as the first parameter)
  543. */
  544. public int getBySubject(int type,Name name,X509Object[] ret) throws Exception {
  545. Store c = ctx;
  546. X509Object tmp = X509Object.retrieveBySubject(c.objs,type,name);
  547. if(tmp == null) {
  548. for(int i=currentMethod; i<c.certificateMethods.size(); i++) {
  549. Lookup lu = c.certificateMethods.get(i);
  550. X509Object[] stmp = new X509Object[1];
  551. int j = lu.bySubject(type,name,stmp);
  552. if(j<0) {
  553. currentMethod = i;
  554. return j;
  555. } else if(j>0) {
  556. tmp = stmp[0];
  557. break;
  558. }
  559. }
  560. currentMethod = 0;
  561. if(tmp == null) {
  562. return 0;
  563. }
  564. }
  565. ret[0] = tmp;
  566. return 1;
  567. }
  568. /**
  569. * c: X509_verify_cert
  570. */
  571. public int verifyCertificate() throws Exception {
  572. X509AuxCertificate x,xtmp=null,chain_ss = null;
  573. //X509_NAME xn;
  574. int bad_chain = 0;
  575. int depth,i,ok=0;
  576. int num;
  577. Store.VerifyCallbackFunction cb;
  578. List<X509AuxCertificate> sktmp = null;
  579. if(certificate == null) {
  580. X509Error.addError(X509Utils.X509_R_NO_CERT_SET_FOR_US_TO_VERIFY);
  581. return -1;
  582. }
  583. cb=verifyCallback;
  584. /* first we make sure the chain we are going to build is
  585. * present and that the first entry is in place */
  586. if(null == chain) {
  587. chain = new ArrayList<X509AuxCertificate>();
  588. chain.add(certificate);
  589. lastUntrusted = 1;
  590. }
  591. /* We use a temporary STACK so we can chop and hack at it */
  592. if(untrusted != null) {
  593. sktmp = new ArrayList<X509AuxCertificate>(untrusted);
  594. }
  595. num = chain.size();
  596. x = chain.get(num-1);
  597. depth = param.depth;
  598. for(;;) {
  599. if(depth < num) {
  600. break;
  601. }
  602. if(checkIssued.call(this,x,x) != 0) {
  603. break;
  604. }
  605. if(untrusted != null) {
  606. xtmp = findIssuer(sktmp,x);
  607. if(xtmp != null) {
  608. chain.add(xtmp);
  609. sktmp.remove(xtmp);
  610. lastUntrusted++;
  611. x = xtmp;
  612. num++;
  613. continue;
  614. }
  615. }
  616. break;
  617. }
  618. /* at this point, chain should contain a list of untrusted
  619. * certificates. We now need to add at least one trusted one,
  620. * if possible, otherwise we complain. */
  621. /* Examine last certificate in chain and see if it
  622. * is self signed.
  623. */
  624. i = chain.size();
  625. x = chain.get(i-1);
  626. if(checkIssued.call(this,x,x) != 0) {
  627. /* we have a self signed certificate */
  628. if(chain.size() == 1) {
  629. /* We have a single self signed certificate: see if
  630. * we can find it in the store. We must have an exact
  631. * match to avoid possible impersonation.
  632. */
  633. X509AuxCertificate[] p_xtmp = new X509AuxCertificate[]{xtmp};
  634. ok = getIssuer.call(p_xtmp,this,x);
  635. xtmp = p_xtmp[0];
  636. if(ok <= 0 || !x.equals(xtmp)) {
  637. error = X509Utils.V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT;
  638. currentCertificate = x;
  639. errorDepth = i-1;
  640. bad_chain = 1;
  641. ok = cb.call(new Integer(0),this);
  642. if(ok == 0) {
  643. return ok;
  644. }
  645. } else {
  646. /* We have a match: replace certificate with store version
  647. * so we get any trust settings.
  648. */
  649. x = xtmp;
  650. chain.set(i-1,x);
  651. lastUntrusted = 0;
  652. }
  653. } else {
  654. /* extract and save self signed certificate for later use */
  655. chain_ss = chain.remove(chain.size()-1);
  656. lastUntrusted--;
  657. num--;
  658. x = chain.get(num-1);
  659. }
  660. }
  661. /* We now lookup certs from the certificate store */
  662. for(;;) {
  663. /* If we have enough, we break */
  664. if(depth<num) {
  665. break;
  666. }
  667. //xn = new X509_NAME(x.getIssuerX500Principal());
  668. /* If we are self signed, we break */
  669. if(checkIssued.call(this,x,x) != 0) {
  670. break;
  671. }
  672. X509AuxCertificate[] p_xtmp = new X509AuxCertificate[]{xtmp};
  673. ok = getIssuer.call(p_xtmp,this,x);
  674. xtmp = p_xtmp[0];
  675. if(ok < 0) {
  676. return ok;
  677. }
  678. if(ok == 0) {
  679. break;
  680. }
  681. x = xtmp;
  682. chain.add(x);
  683. num++;
  684. }
  685. /* we now have our chain, lets check it... */
  686. //xn = new X509_NAME(x.getIssuerX500Principal());
  687. /* Is last certificate looked up self signed? */
  688. if(checkIssued.call(this,x,x) == 0) {
  689. if(chain_ss == null || checkIssued.call(this,x,chain_ss) == 0) {
  690. if(lastUntrusted >= num) {
  691. error = X509Utils.V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY;
  692. } else {
  693. error = X509Utils.V_ERR_UNABLE_TO_GET_ISSUER_CERT;
  694. }
  695. currentCertificate = x;
  696. } else {
  697. chain.add(chain_ss);
  698. num++;
  699. lastUntrusted = num;
  700. currentCertificate = chain_ss;
  701. error = X509Utils.V_ERR_SELF_SIGNED_CERT_IN_CHAIN;
  702. chain_ss = null;
  703. }
  704. errorDepth = num-1;
  705. bad_chain = 1;
  706. ok = cb.call(new Integer(0),this);
  707. if(ok == 0) {
  708. return ok;
  709. }
  710. }
  711. /* We have the chain complete: now we need to check its purpose */
  712. ok = checkChainExtensions();
  713. if(ok == 0) {
  714. return ok;
  715. }
  716. /* TODO: Check name constraints (from 1.0.0) */
  717. /* The chain extensions are OK: check trust */
  718. if(param.trust > 0) {
  719. ok = checkTrust();
  720. }
  721. if(ok == 0) {
  722. return ok;
  723. }
  724. /* Check revocation status: we do this after copying parameters
  725. * because they may be needed for CRL signature verification.
  726. */
  727. ok = checkRevocation.call(this);
  728. if(ok == 0) {
  729. return ok;
  730. }
  731. /* At this point, we have a chain and need to verify it */
  732. if(verify != null && verify != Store.VerifyFunction.EMPTY) {
  733. ok = verify.call(this);
  734. } else {
  735. ok = internalVerify.call(this);
  736. }
  737. if(ok == 0) {
  738. return ok;
  739. }
  740. /* TODO: RFC 3779 path validation, now that CRL check has been done (from 1.0.0) */
  741. /* If we get this far evaluate policies */
  742. if(bad_chain == 0 && (param.flags & X509Utils.V_FLAG_POLICY_CHECK) != 0) {
  743. ok = checkPolicy.call(this);
  744. }
  745. return ok;
  746. }
  747. private final static Set<String> CRITICAL_EXTENSIONS = new HashSet<String>();
  748. static {
  749. CRITICAL_EXTENSIONS.add("2.16.840.1.113730.1.1"); // netscape cert type, NID 71
  750. CRITICAL_EXTENSIONS.add("2.5.29.15"); // key usage, NID 83
  751. CRITICAL_EXTENSIONS.add("2.5.29.17"); // subject alt name, NID 85
  752. CRITICAL_EXTENSIONS.add("2.5.29.19"); // basic constraints, NID 87
  753. CRITICAL_EXTENSIONS.add("2.5.29.37"); // ext key usage, NID 126
  754. CRITICAL_EXTENSIONS.add("1.3.6.1.5.5.7.1.14"); // proxy cert info, NID 661
  755. }
  756. private static boolean supportsCriticalExtension(String oid) {
  757. return CRITICAL_EXTENSIONS.contains(oid);
  758. }
  759. private static boolean unhandledCritical(X509Extension xx) {
  760. if(xx.getCriticalExtensionOIDs() == null || xx.getCriticalExtensionOIDs().size() == 0) {
  761. return false;
  762. }
  763. for(String ss : xx.getCriticalExtensionOIDs()) {
  764. if(!supportsCriticalExtension(ss)) {
  765. return true;
  766. }
  767. }
  768. return false;
  769. }
  770. /**
  771. * c: check_chain_extensions
  772. */
  773. public int checkChainExtensions() throws Exception {
  774. int ok=0, must_be_ca;
  775. X509AuxCertificate x;
  776. Store.VerifyCallbackFunction cb;
  777. int proxy_path_length = 0;
  778. int allow_proxy_certs = (param.flags & X509Utils.V_FLAG_ALLOW_PROXY_CERTS) != 0 ? 1 : 0;
  779. cb = verifyCallback;
  780. must_be_ca = -1;
  781. try {
  782. if (System.getenv("OPENSSL_ALLOW_PROXY_CERTS") != null && !"false".equalsIgnoreCase(System.getenv("OPENSSL_ALLOW_PROXY_CERTS"))) {
  783. allow_proxy_certs = 1;
  784. }
  785. } catch (Error e) {
  786. // just ignore if we can't use System.getenv
  787. }
  788. for(int i = 0; i<lastUntrusted;i++) {
  789. int ret;
  790. x = chain.get(i);
  791. if((param.flags & X509Utils.V_FLAG_IGNORE_CRITICAL) == 0 && unhandledCritical(x)) {
  792. error = X509Utils.V_ERR_UNHANDLED_CRITICAL_EXTENSION;
  793. errorDepth = i;
  794. currentCertificate = x;
  795. ok = cb.call(new Integer(0),this);
  796. if(ok == 0) {
  797. return ok;
  798. }
  799. }
  800. if(allow_proxy_certs == 0 && x.getExtensionValue("1.3.6.1.5.5.7.1.14") != null) {
  801. error = X509Utils.V_ERR_PROXY_CERTIFICATES_NOT_ALLOWED;
  802. errorDepth = i;
  803. currentCertificate = x;
  804. ok = cb.call(new Integer(0),this);
  805. if(ok == 0) {
  806. return ok;
  807. }
  808. }
  809. ret = Purpose.checkCA(x);
  810. switch(must_be_ca) {
  811. case -1:
  812. if((param.flags & X509Utils.V_FLAG_X509_STRICT) != 0 && ret != 1 && ret != 0) {
  813. ret = 0;
  814. error = X509Utils.V_ERR_INVALID_CA;
  815. } else {
  816. ret = 1;
  817. }
  818. break;
  819. case 0:
  820. if(ret != 0) {
  821. ret = 0;
  822. error = X509Utils.V_ERR_INVALID_NON_CA;
  823. } else {
  824. ret = 1;
  825. }
  826. break;
  827. default:
  828. if(ret == 0 || ((param.flags & X509Utils.V_FLAG_X509_STRICT) != 0 && ret != 1)) {
  829. ret = 0;
  830. error = X509Utils.V_ERR_INVALID_CA;
  831. } else {
  832. ret = 1;
  833. }
  834. break;
  835. }
  836. if(ret == 0) {
  837. errorDepth = i;
  838. currentCertificate = x;
  839. ok = cb.call(new Integer(0),this);
  840. if(ok == 0) {
  841. return ok;
  842. }
  843. }
  844. if(param.purpose > 0) {
  845. ret = Purpose.checkPurpose(x,param.purpose, must_be_ca > 0 ? 1 : 0);
  846. if(ret == 0 || ((param.flags & X509Utils.V_FLAG_X509_STRICT) != 0 && ret != 1)) {
  847. error = X509Utils.V_ERR_INVALID_PURPOSE;
  848. errorDepth = i;
  849. currentCertificate = x;
  850. ok = cb.call(new Integer(0),this);
  851. if(ok == 0) {
  852. return ok;
  853. }
  854. }
  855. }
  856. if(i > 1 && x.getBasicConstraints() != -1 && x.getBasicConstraints() != Integer.MAX_VALUE && (i > (x.getBasicConstraints() + proxy_path_length + 1))) {
  857. error = X509Utils.V_ERR_PATH_LENGTH_EXCEEDED;
  858. errorDepth = i;
  859. currentCertificate = x;
  860. ok = cb.call(new Integer(0),this);
  861. if(ok == 0) {
  862. return ok;
  863. }
  864. }
  865. if(x.getExtensionValue("1.3.6.1.5.5.7.1.14") != null) {
  866. ASN1Sequence pci = (ASN1Sequence)new ASN1InputStream(x.getExtensionValue("1.3.6.1.5.5.7.1.14")).readObject();
  867. if(pci.size() > 0 && pci.getObjectAt(0) instanceof ASN1Integer) {
  868. int pcpathlen = ((ASN1Integer)pci.getObjectAt(0)).getValue().intValue();
  869. if(i > pcpathlen) {
  870. error = X509Utils.V_ERR_PROXY_PATH_LENGTH_EXCEEDED;
  871. errorDepth = i;
  872. currentCertificate = x;
  873. ok = cb.call(new Integer(0),this);
  874. if(ok == 0) {
  875. return ok;
  876. }
  877. }
  878. }
  879. proxy_path_length++;
  880. must_be_ca = 0;
  881. } else {
  882. must_be_ca = 1;
  883. }
  884. }
  885. return 1;
  886. }
  887. /**
  888. * c: X509_check_trust
  889. */
  890. public int checkTrust() throws Exception {
  891. int i,ok;
  892. X509AuxCertificate x;
  893. Store.VerifyCallbackFunction cb;
  894. cb = verifyCallback;
  895. i = chain.size()-1;
  896. x = chain.get(i);
  897. ok = Trust.checkTrust(x,param.trust,0);
  898. if(ok == X509Utils.X509_TRUST_TRUSTED) {
  899. return 1;
  900. }
  901. errorDepth = 1;
  902. currentCertificate = x;
  903. if(ok == X509Utils.X509_TRUST_REJECTED) {
  904. error = X509Utils.V_ERR_CERT_REJECTED;
  905. } else {
  906. error = X509Utils.V_ERR_CERT_UNTRUSTED;
  907. }
  908. return cb.call(new Integer(0),this);
  909. }
  910. /**
  911. * c: check_cert_time
  912. */
  913. public int checkCertificateTime(X509AuxCertificate x) throws Exception {
  914. Date ptime = null;
  915. if((param.flags & X509Utils.V_FLAG_USE_CHECK_TIME) != 0) {
  916. ptime = this.param.checkTime;
  917. } else {
  918. ptime = Calendar.getInstance().getTime();
  919. }
  920. if(!x.getNotBefore().before(ptime)) {
  921. error = X509Utils.V_ERR_CERT_NOT_YET_VALID;
  922. currentCertificate = x;
  923. if(verifyCallback.call(new Integer(0),this) == 0) {
  924. return 0;
  925. }
  926. }
  927. if(!x.getNotAfter().after(ptime)) {
  928. error = X509Utils.V_ERR_CERT_HAS_EXPIRED;
  929. currentCertificate = x;
  930. if(verifyCallback.call(new Integer(0),this) == 0) {
  931. return 0;
  932. }
  933. }
  934. return 1;
  935. }
  936. /**
  937. * c: check_cert
  938. */
  939. public int checkCertificate() throws Exception {
  940. X509CRL[] crl = new X509CRL[1];
  941. X509AuxCertificate x;
  942. int ok,cnum;
  943. cnum = errorDepth;
  944. x = chain.get(cnum);
  945. currentCertificate = x;
  946. ok = getCRL.call(this,crl,x);
  947. if(ok == 0) {
  948. error = X509Utils.V_ERR_UNABLE_TO_GET_CRL;
  949. ok = verifyCallback.call(new Integer(0), this);
  950. currentCRL = null;
  951. return ok;
  952. }
  953. currentCRL = crl[0];
  954. ok = checkCRL.call(this, crl[0]);
  955. if(ok == 0) {
  956. currentCRL = null;
  957. return ok;
  958. }
  959. ok = certificateCRL.call(this,crl[0],x);
  960. currentCRL = null;
  961. return ok;
  962. }
  963. /**
  964. * c: check_crl_time
  965. */
  966. public int checkCRLTime(X509CRL crl, int notify) throws Exception {
  967. currentCRL = crl;
  968. Date ptime = null;
  969. if((param.flags & X509Utils.V_FLAG_USE_CHECK_TIME) != 0) {
  970. ptime = this.param.checkTime;
  971. } else {
  972. ptime = Calendar.getInstance().getTime();
  973. }
  974. if(!crl.getThisUpdate().before(ptime)) {
  975. error=X509Utils.V_ERR_CRL_NOT_YET_VALID;
  976. if(notify == 0 || verifyCallback.call(new Integer(0),this) == 0) {
  977. return 0;
  978. }
  979. }
  980. if(crl.getNextUpdate() != null && !crl.getNextUpdate().after(ptime)) {
  981. error=X509Utils.V_ERR_CRL_HAS_EXPIRED;
  982. if(notify == 0 || verifyCallback.call(new Integer(0),this) == 0) {
  983. return 0;
  984. }
  985. }
  986. currentCRL = null;
  987. return 1;
  988. }
  989. /**
  990. * c: get_crl_sk
  991. */
  992. public int getCRLStack(X509CRL[] pcrl, Name nm, List<X509CRL> crls) throws Exception {
  993. X509CRL best_crl = null;
  994. if(null != crls) {
  995. for(X509CRL crl : crls) {
  996. if(!nm.isEqual(crl.getIssuerX500Principal())) {
  997. continue;
  998. }
  999. if(checkCRLTime(crl,0) != 0) {
  1000. pcrl[0] = crl;
  1001. return 1;
  1002. }
  1003. best_crl = crl;
  1004. }
  1005. }
  1006. if(best_crl != null) {
  1007. pcrl[0] = best_crl;
  1008. }
  1009. return 0;
  1010. }
  1011. /**
  1012. * c: get_issuer_sk
  1013. */
  1014. public final static Store.GetIssuerFunction getIssuerStack = new Store.GetIssuerFunction() {
  1015. public int call(Object a1, Object a2, Object a3) throws Exception {
  1016. X509AuxCertificate[] issuer = (X509AuxCertificate[])a1;
  1017. StoreContext ctx = (StoreContext)a2;
  1018. X509AuxCertificate x = (X509AuxCertificate)a3;
  1019. issuer[0] = ctx.findIssuer(ctx.otherContext,x);
  1020. if(issuer[0] != null) {
  1021. return 1;
  1022. } else {
  1023. return 0;
  1024. }
  1025. }
  1026. };
  1027. /**
  1028. * c: check_issued
  1029. */
  1030. public final static Store.CheckIssuedFunction defaultCheckIssued = new Store.CheckIssuedFunction() {
  1031. public int call(Object a1, Object a2, Object a3) throws Exception {
  1032. StoreContext ctx = (StoreContext)a1;
  1033. X509AuxCertificate x = (X509AuxCertificate)a2;
  1034. X509AuxCertificate issuer = (X509AuxCertificate)a3;
  1035. int ret = X509Utils.checkIfIssuedBy(issuer,x);
  1036. if(ret == X509Utils.V_OK) {
  1037. return 1;
  1038. }
  1039. if((ctx.param.flags & X509Utils.V_FLAG_CB_ISSUER_CHECK) == 0) {
  1040. return 0;
  1041. }
  1042. ctx.error = ret;
  1043. ctx.currentCertificate = x;
  1044. ctx.currentIssuer = issuer;
  1045. return ctx.verifyCallback.call(new Integer(0),ctx);
  1046. }
  1047. };
  1048. /**
  1049. * c: null_callback
  1050. */
  1051. public final static Store.VerifyCallbackFunction NullCallback = new Store.VerifyCallbackFunction() {
  1052. public int call(Object a1, Object a2) {
  1053. return ((Integer)a1).intValue();
  1054. }
  1055. };
  1056. /**
  1057. * c: internal_verify
  1058. */
  1059. public final static Store.VerifyFunction internalVerify = new Store.VerifyFunction() {
  1060. public int call(Object a1) throws Exception {
  1061. StoreContext ctx = (StoreContext)a1;
  1062. Store.VerifyCallbackFunction cb = ctx.verifyCallback;
  1063. int n = ctx.chain.size();
  1064. ctx.errorDepth = n-1;
  1065. n--;
  1066. X509AuxCertificate xi = ctx.chain.get(n);
  1067. X509AuxCertificate xs = null;
  1068. int ok = 0;
  1069. if(ctx.checkIssued.call(ctx,xi,xi) != 0) {
  1070. xs = xi;
  1071. } else {
  1072. if(n<=0) {
  1073. ctx.error = X509Utils.V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE;
  1074. ctx.currentCertificate = xi;
  1075. ok = cb.call(new Integer(0),ctx);
  1076. return ok;
  1077. } else {
  1078. n--;
  1079. ctx.errorDepth = n;
  1080. xs = ctx.chain.get(n);
  1081. }
  1082. }
  1083. while(n>=0) {
  1084. ctx.errorDepth = n;
  1085. if(!xs.isValid()) {
  1086. try {
  1087. xs.verify(xi.getPublicKey());
  1088. } catch(Exception e) {
  1089. /*
  1090. System.err.println("n: " + n);
  1091. System.err.println("verifying: " + xs);
  1092. System.err.println("verifying with issuer?: " + xi);
  1093. System.err.println("verifying with issuer.key?: " + xi.getPublicKey());
  1094. System.err.println("exception: " + e);
  1095. */
  1096. ctx.error = X509Utils.V_ERR_CERT_SIGNATURE_FAILURE;
  1097. ctx.currentCertificate = xs;
  1098. ok = cb.call(new Integer(0),ctx);
  1099. if(ok == 0) {
  1100. return ok;
  1101. }
  1102. }
  1103. }
  1104. xs.setValid(true);
  1105. ok = ctx.checkCertificateTime(xs);
  1106. if(ok == 0) {
  1107. return ok;
  1108. }
  1109. ctx.currentIssuer = xi;
  1110. ctx.currentCertificate = xs;
  1111. ok = cb.call(new Integer(1),ctx);
  1112. if(ok == 0) {
  1113. return ok;
  1114. }
  1115. n--;
  1116. if(n>=0) {
  1117. xi = xs;
  1118. xs = ctx.chain.get(n);
  1119. }
  1120. }
  1121. ok = 1;
  1122. return ok;
  1123. }
  1124. };
  1125. /**
  1126. * c: check_revocation
  1127. */
  1128. public final static Store.CheckRevocationFunction defaultCheckRevocation = new Store.CheckRevocationFunction() {
  1129. public int call(Object a1) throws Exception {
  1130. StoreContext ctx = (StoreContext)a1;
  1131. int last,ok=0;
  1132. if((ctx.param.flags & X509Utils.V_FLAG_CRL_CHECK) == 0) {
  1133. return 1;
  1134. }
  1135. if((ctx.param.flags & X509Utils.V_FLAG_CRL_CHECK_ALL) != 0) {
  1136. last = ctx.chain.size() -1;
  1137. } else {
  1138. last = 0;
  1139. }
  1140. for(int i=0;i<=last;i++) {
  1141. ctx.errorDepth = i;
  1142. ok = ctx.checkCertificate();
  1143. if(ok == 0) {
  1144. return 0;
  1145. }
  1146. }
  1147. return 1;
  1148. }
  1149. };
  1150. /**
  1151. * c: get_crl
  1152. */
  1153. public final static Store.GetCRLFunction defaultGetCRL = new Store.GetCRLFunction() {
  1154. public int call(Object a1, Object a2, Object a3) throws Exception {
  1155. StoreContext ctx = (StoreContext)a1;
  1156. X509CRL[] pcrl = (X509CRL[])a2;
  1157. X509AuxCertificate x = (X509AuxCertificate)a3;
  1158. Name nm = new Name(x.getIssuerX500Principal());
  1159. X509CRL[] crl = new X509CRL[1];
  1160. int ok = ctx.getCRLStack(crl,nm,ctx.crls);
  1161. if(ok != 0) {
  1162. pcrl[0] = crl[0];
  1163. return 1;
  1164. }
  1165. X509Object[] xobj = new X509Object[1];
  1166. ok = ctx.getBySubject(X509Utils.X509_LU_CRL,nm,xobj);
  1167. if(ok == 0) {
  1168. if(crl[0] != null) {
  1169. pcrl[0] = crl[0];
  1170. return 1;
  1171. }
  1172. return 0;
  1173. }
  1174. pcrl[0] = (X509CRL)(((CRL)xobj[0]).crl);
  1175. return 1;
  1176. }
  1177. };
  1178. /**
  1179. * c: check_crl
  1180. */
  1181. public final static Store.CheckCRLFunction defaultCheckCRL = new Store.CheckCRLFunction() {
  1182. public int call(Object a1, Object a2) throws Exception {
  1183. StoreContext ctx = (StoreContext)a1;
  1184. final X509CRL crl = (X509CRL)a2;
  1185. X509AuxCertificate issuer = null;
  1186. int ok = 0,chnum,cnum;
  1187. cnum = ctx.errorDepth;
  1188. chnum = ctx.chain.size()-1;
  1189. if(cnum < chnum) {
  1190. issuer = ctx.chain.get(cnum+1);
  1191. } else {
  1192. issuer = ctx.chain.get(chnum);
  1193. if(ctx.checkIssued.call(ctx,issuer,issuer) == 0) {
  1194. ctx.error = X509Utils.V_ERR_UNABLE_TO_GET_CRL_ISSUER;
  1195. ok = ctx.verifyCallback.call(new Integer(0),ctx);
  1196. if(ok == 0) {
  1197. return ok;
  1198. }
  1199. }
  1200. }
  1201. if (issuer != null) {
  1202. if (issuer.getKeyUsage() != null && !issuer.getKeyUsage()[6]) {
  1203. ctx.error = X509Utils.V_ERR_KEYUSAGE_NO_CRL_SIGN;
  1204. ok = ctx.verifyCallback.call(new Integer(0), ctx);
  1205. if (ok == 0) {
  1206. return ok;
  1207. }
  1208. }
  1209. final PublicKey ikey = issuer.getPublicKey();
  1210. if (ikey == null) {
  1211. ctx.error = X509Utils.V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY;
  1212. ok = ctx.verifyCallback.call(new Integer(0), ctx);
  1213. if (ok == 0) {
  1214. return ok;
  1215. }
  1216. } else {
  1217. try {
  1218. crl.verify(ikey);
  1219. } catch (Exception ignored) {
  1220. ctx.error = X509Utils.V_ERR_CRL_SIGNATURE_FAILURE;
  1221. ok = ctx.verifyCallback.call(new Integer(0), ctx);
  1222. if (ok == 0) {
  1223. return ok;
  1224. }
  1225. }
  1226. }
  1227. }
  1228. ok = ctx.checkCRLTime(crl,1);
  1229. if(ok == 0) {
  1230. return ok;
  1231. }
  1232. return 1;
  1233. }
  1234. };
  1235. /**
  1236. * c: cert_crl
  1237. */
  1238. public final static Store.CertificateCRLFunction defaultCertificateCRL = new Store.CertificateCRLFunction() {
  1239. public int call(Object a1, Object a2, Object a3) throws Exception {
  1240. StoreContext ctx = (StoreContext)a1;
  1241. X509CRL crl = (X509CRL)a2;
  1242. X509AuxCertificate x = (X509AuxCertificate)a3;
  1243. int ok;
  1244. if(crl.getRevokedCertificate(x.getSerialNumber()) != null) {
  1245. ctx.error = X509Utils.V_ERR_CERT_REVOKED;
  1246. ok = ctx.verifyCallback.call(new Integer(0), ctx);
  1247. if(ok == 0) {
  1248. return 0;
  1249. }
  1250. }
  1251. if((ctx.param.flags & X509Utils.V_FLAG_IGNORE_CRITICAL) != 0) {
  1252. return 1;
  1253. }
  1254. if(crl.getCriticalExtensionOIDs() != null && crl.getCriticalExtensionOIDs().size()>0) {
  1255. ctx.error = X509Utils.V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION;
  1256. ok = ctx.verifyCallback.call(new Integer(0), ctx);
  1257. if(ok == 0) {
  1258. return 0;
  1259. }
  1260. }
  1261. return 1;
  1262. }
  1263. };
  1264. /**
  1265. * c: check_policy
  1266. */
  1267. public final static CheckPolicyFunction defaultCheckPolicy = new CheckPolicyFunction() {
  1268. public int call(Object a1) throws Exception {
  1269. return 1;
  1270. }
  1271. };
  1272. }// X509_STORE_CTX