示例#1
0
        public override String ToString()
        {
            String s = "Certificate name:\n";

            s += "  " + getName().toUri() + "\n";
            s += "Validity:\n";

            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd'T'HHmmss");

            dateFormat.setTimeZone(System.Collections.TimeZone.getTimeZone("UTC"));
            String notBeforeStr = dateFormat
                                  .format(net.named_data.jndn.util.Common.millisecondsSince1970ToDate((long)Math.Round(getNotBefore(), MidpointRounding.AwayFromZero)));
            String notAfterStr = dateFormat.format(net.named_data.jndn.util.Common
                                                   .millisecondsSince1970ToDate((long)Math.Round(getNotAfter(), MidpointRounding.AwayFromZero)));

            s += "  NotBefore: " + notBeforeStr + "\n";
            s += "  NotAfter: " + notAfterStr + "\n";
            for (int i = 0; i < subjectDescriptionList_.Count; ++i)
            {
                CertificateSubjectDescription sd = (CertificateSubjectDescription)subjectDescriptionList_[i];
                s += "Subject Description:\n";
                s += "  " + sd.getOidString() + ": " + sd.getValue() + "\n";
            }

            s += "Public key bits:\n";
            Blob   keyDer     = getPublicKeyDer();
            String encodedKey = net.named_data.jndn.util.Common.base64Encode(keyDer.getImmutableArray());

            for (int i_0 = 0; i_0 < encodedKey.Length; i_0 += 64)
            {
                s += encodedKey.Substring(i_0, (Math.Min(i_0 + 64, encodedKey.Length)) - (i_0))
                     + "\n";
            }

            if (extensionList_.Count > 0)
            {
                s += "Extensions:\n";
                for (int i_1 = 0; i_1 < extensionList_.Count; ++i_1)
                {
                    CertificateExtension ext = (CertificateExtension)extensionList_[i_1];
                    s += "  OID: " + ext.getOid() + "\n";
                    s += "  Is critical: " + ((ext.getIsCritical()) ? 'Y' : 'N')
                         + "\n";

                    s += "  Value: " + ext.getValue().toHex() + "\n";
                }
            }

            return(s);
        }
示例#2
0
 /// <summary>
 /// Add a certificate extension.
 /// </summary>
 ///
 /// <param name="extension">the extension to be added</param>
 public void addExtension(CertificateExtension extension)
 {
     ILOG.J2CsMapping.Collections.Collections.Add(extensionList_,extension);
 }
示例#3
0
 /// <summary>
 /// Add a certificate extension.
 /// </summary>
 ///
 /// <param name="extension">the extension to be added</param>
 public void addExtension(CertificateExtension extension)
 {
     ILOG.J2CsMapping.Collections.Collections.Add(extensionList_, extension);
 }
        public void testExtension()
        {
            // Now add an extension.
            String name = "/hello/kitty";
            int trustClass = 0;
            int trustLevel = 300;

            net.named_data.jndn.encoding.der.DerNode.DerSequence  extValueRoot = new net.named_data.jndn.encoding.der.DerNode.DerSequence ();
            net.named_data.jndn.encoding.der.DerNode.DerOctetString  extValueName = new net.named_data.jndn.encoding.der.DerNode.DerOctetString (new Blob(name).buf());
            net.named_data.jndn.encoding.der.DerNode.DerInteger  extValueTrustClass = new net.named_data.jndn.encoding.der.DerNode.DerInteger (trustClass);
            net.named_data.jndn.encoding.der.DerNode.DerInteger  extValueTrustLevel = new net.named_data.jndn.encoding.der.DerNode.DerInteger (trustLevel);

            extValueRoot.addChild(extValueName);
            extValueRoot.addChild(extValueTrustClass);
            extValueRoot.addChild(extValueTrustLevel);

            Blob extValueData = extValueRoot.encode();

            String oidString = "1.3.6.1.5.32.1";
            bool isCritical = true;
            CertificateExtension certExtension = new CertificateExtension(
                    oidString, isCritical, extValueData);
            toyCert.encode();
            Certificate cert = new Certificate(toyCert);
            cert.addExtension(certExtension);

            cert.encode();
            Blob certData = cert.getContent();
            Data plainData = new Data();
            plainData.setContent(certData);
            // The constructor Certificate(Data) calls decode().
            Certificate decodedCert = new Certificate(plainData);
            Assert.AssertEquals("Wrong number of certificate extensions after decoding",
                    1, decodedCert.getExtensionList().Count);

            CertificateExtension decodedExtension = (CertificateExtension) decodedCert
                            .getExtensionList()[0];
            Assert.AssertEquals("Certificate extension has the wrong OID after decoding",
                    oidString, "" + decodedExtension.getOid());
            Assert.AssertEquals(
                    "Certificate extension has the wrong isCritical value after decoding",
                    isCritical, decodedExtension.getIsCritical());

            // Decode and check the extension value.
            DerNode parsedExtValue = net.named_data.jndn.encoding.der.DerNode.parse(decodedExtension.getValue()
                    .buf());
            IList decodedExtValueRoot = parsedExtValue.getChildren();
            Assert.AssertEquals(
                    "Wrong number of certificate extension value items after decoding",
                    3, decodedExtValueRoot.Count);

            net.named_data.jndn.encoding.der.DerNode.DerOctetString  decodedName = (net.named_data.jndn.encoding.der.DerNode.DerOctetString ) decodedExtValueRoot[0];
            net.named_data.jndn.encoding.der.DerNode.DerInteger  decodedTrustClass = (net.named_data.jndn.encoding.der.DerNode.DerInteger ) decodedExtValueRoot[1];
            net.named_data.jndn.encoding.der.DerNode.DerInteger  decodedTrustLevel = (net.named_data.jndn.encoding.der.DerNode.DerInteger ) decodedExtValueRoot[2];
            Assert.AssertEquals("Wrong extension value name after decoding", name, ""
                    + decodedName.toVal());
            Assert.AssertEquals("Wrong extension value trust class after decoding",
                    trustClass, (int) (Int32) decodedTrustClass.toVal());
            Assert.AssertEquals("Wrong extension value trust level after decoding",
                    trustLevel, (int) (Int32) decodedTrustLevel.toVal());
        }