diff options
author | burdziak <olaf.burdziakowski@nokia.com> | 2018-05-22 11:22:46 +0200 |
---|---|---|
committer | burdziak <olaf.burdziakowski@nokia.com> | 2018-05-22 11:22:46 +0200 |
commit | 3c0c0a519559fcb3ff4b2a65474b5128b73ccd2c (patch) | |
tree | 56d005deaa37340bf08e8eb4ada71cf71242316f | |
parent | c8f8273a200559f87b883767758e4bda446dadfe (diff) |
Fix sonar issue in CSRMeta
Change-Id: I2f48381e27f799a0b4e1a5cf0a6c95a564a3c7c7
Issue-ID: AAF-311
Signed-off-by: burdziak <olaf.burdziakowski@nokia.com>
-rw-r--r-- | auth/auth-certman/src/main/java/org/onap/aaf/auth/cm/cert/CSRMeta.java | 62 |
1 files changed, 30 insertions, 32 deletions
diff --git a/auth/auth-certman/src/main/java/org/onap/aaf/auth/cm/cert/CSRMeta.java b/auth/auth-certman/src/main/java/org/onap/aaf/auth/cm/cert/CSRMeta.java index 2541bea0..2b763f7f 100644 --- a/auth/auth-certman/src/main/java/org/onap/aaf/auth/cm/cert/CSRMeta.java +++ b/auth/auth-certman/src/main/java/org/onap/aaf/auth/cm/cert/CSRMeta.java @@ -60,17 +60,16 @@ public class CSRMeta { private String email; private String challenge; private List<RDN> rdns; - - public CSRMeta(List<RDN> rdns) { - this.rdns = rdns; - } - - private ArrayList<String> sanList = new ArrayList<String>(); + private ArrayList<String> sanList = new ArrayList<>(); private KeyPair keyPair; private X500Name name = null; private SecureRandom random = new SecureRandom(); - public X500Name x500Name() throws IOException { + public CSRMeta(List<RDN> rdns) { + this.rdns = rdns; + } + + public X500Name x500Name() { if(name==null) { X500NameBuilder xnb = new X500NameBuilder(); xnb.addRDN(BCStyle.CN,cn); @@ -99,7 +98,7 @@ public class CSRMeta { } int plus = email==null?0:1; - if(sanList.size()>0) { + if(!sanList.isEmpty()) { GeneralName[] gna = new GeneralName[sanList.size()+plus]; int i=-1; for(String s : sanList) { @@ -114,10 +113,7 @@ public class CSRMeta { }) ); } - - if(email!=null) { - - } + try { return builder.build(BCFactory.contentSigner(keypair(trans).getPrivate())); } catch (OperatorCreationException e) { @@ -129,27 +125,29 @@ public class CSRMeta { public static void dump(PKCS10CertificationRequest csr) { Attribute[] certAttributes = csr.getAttributes(); for (Attribute attribute : certAttributes) { - if (attribute.getAttrType().equals(PKCSObjectIdentifiers.pkcs_9_at_extensionRequest)) { - Extensions extensions = Extensions.getInstance(attribute.getAttrValues().getObjectAt(0)); - GeneralNames gns = GeneralNames.fromExtensions(extensions,Extension.subjectAlternativeName); - GeneralName[] names = gns.getNames(); - for(int k=0; k < names.length; k++) { - String title = ""; - if(names[k].getTagNo() == GeneralName.dNSName) { - title = "dNSName"; - } else if(names[k].getTagNo() == GeneralName.iPAddress) { - title = "iPAddress"; - // Deprecated, but I don't see anything better to use. - names[k].toASN1Object(); - } else if(names[k].getTagNo() == GeneralName.otherName) { - title = "otherName"; - } else if(names[k].getTagNo() == GeneralName.rfc822Name) { - title = "email"; - } + if (!attribute.getAttrType().equals(PKCSObjectIdentifiers.pkcs_9_at_extensionRequest)) { + continue; + } + + Extensions extensions = Extensions.getInstance(attribute.getAttrValues().getObjectAt(0)); + GeneralNames gns = GeneralNames.fromExtensions(extensions,Extension.subjectAlternativeName); + GeneralName[] names = gns.getNames(); + for(int k=0; k < names.length; k++) { + String title = ""; + if(names[k].getTagNo() == GeneralName.dNSName) { + title = "dNSName"; + } else if(names[k].getTagNo() == GeneralName.iPAddress) { + title = "iPAddress"; + // Deprecated, but I don't see anything better to use. + names[k].toASN1Object(); + } else if(names[k].getTagNo() == GeneralName.otherName) { + title = "otherName"; + } else if(names[k].getTagNo() == GeneralName.rfc822Name) { + title = "email"; + } - System.out.println(title + ": "+ names[k].getName()); - } - } + System.out.println(title + ": "+ names[k].getName()); + } } } |