Esempio n. 1
0
        public SuggestFunctionTextBox()
        {
            var signatureFactory = new SignatureFactory();

            _tokenCompleter = new TokenCompleter(signatureFactory.GetSignatureService());
            InitializeComponent();
            InitializeTooltip();
        }
Esempio n. 2
0
        public MainPage()
        {
            var signatureFactory = new SignatureFactory();

            Task.Run(() => new TokenCompleter(signatureFactory.GetSignatureService()))
            .ContinueWith((res) =>
            {
                _tokenCompleter = res.Result;
            }
                          );
            this.InitializeComponent();
        }
Esempio n. 3
0
        public void TestSignatureFactoryStringInput()
        {
            SignatureFactory f      = new SignatureFactory();
            string           buffer = "abcdefghijklmnopqrstuvwxyz";

            string signature1 = f.Sign(buffer);

            Assert.IsTrue(f.Verify(buffer, signature1), "(1) correct signature verification");
            Assert.IsFalse(f.Verify(new string(buffer.Reverse().ToArray()), signature1), "(2) incorrect signature verification");

            // Test new Encryption instance based on existing Key and IV.
            f = new SignatureFactory(f.ExportPrivateKey());
            string signature2 = f.Sign(buffer);

            Assert.IsTrue(f.Verify(buffer, signature1), "(3) correct signature verification ");
            Assert.IsTrue(f.Verify(buffer, signature2), "(4) correct signature verification ");
            Assert.IsFalse(f.Verify(new string(buffer.Reverse().ToArray()), signature2), "(5) incorrect signature verification");

            Assert.AreNotEqual(buffer, signature1, "(6) signature should not be the same as original data");
        }
Esempio n. 4
0
        public void TestSignatureFactoryByteArrayInput()
        {
            SignatureFactory f = new SignatureFactory();

            byte[] buffer = new byte[300];
            new Random().NextBytes(buffer);

            byte[] signature1 = f.Sign(buffer);
            Assert.AreNotEqual(string.Join(",", buffer), string.Join(",", signature1), "signature should not be the same as original data");
            Assert.IsTrue(f.Verify(buffer, signature1), "(1) correct signature verification");
            Assert.IsFalse(f.Verify(buffer.Reverse().ToArray(), signature1), "(2) incorrect signature verification");
            Assert.IsFalse(f.Verify(buffer, signature1.Reverse().ToArray()), "(3) incorrect signature verification");

            // Test new Encryption instance based on existing Key and IV.
            f = new SignatureFactory(f.ExportPrivateKey());
            byte[] signature2 = f.Sign(buffer);
            Assert.IsTrue(f.Verify(buffer, signature1), "(4) correct signature verification ");
            Assert.IsTrue(f.Verify(buffer, signature2), "(5) correct signature verification ");
            Assert.IsFalse(f.Verify(buffer.Reverse().ToArray(), signature2), "(6) incorrect signature verification");
            Assert.IsFalse(f.Verify(buffer, signature2.Reverse().ToArray()), "(7) incorrect signature verification");

            Assert.AreNotEqual(buffer, signature1, "(8) signature should not be the same as original data");
        }
Esempio n. 5
0
        /// <inheritdoc/>
        public Task <Crl> CreateCrlAsync(Certificate issuer, SignatureType signature,
                                         IEnumerable <Certificate> revokedCertificates, DateTime?nextUpdate,
                                         CancellationToken ct)
        {
            try {
                if (issuer == null)
                {
                    throw new ArgumentNullException(nameof(issuer));
                }
                if (issuer.RawData == null)
                {
                    throw new ArgumentNullException(nameof(issuer.RawData));
                }
                if (issuer.IssuerPolicies == null)
                {
                    throw new ArgumentNullException(nameof(issuer.IssuerPolicies));
                }
                if (issuer.KeyHandle == null)
                {
                    throw new ArgumentNullException(nameof(issuer.KeyHandle));
                }

                var bcCertCA   = new X509CertificateParser().ReadCertificate(issuer.RawData);
                var thisUpdate = DateTime.UtcNow;
                var crlGen     = new X509V2CrlGenerator();

                crlGen.SetIssuerDN(bcCertCA.SubjectDN);
                crlGen.SetThisUpdate(DateTime.UtcNow);
                crlGen.SetNextUpdate(nextUpdate ?? issuer.NotAfterUtc);

                if (revokedCertificates == null || !revokedCertificates.Any())
                {
                    // add a dummy entry
                    crlGen.AddCrlEntry(BigInteger.One, thisUpdate, CrlReason.Unspecified);
                }
                else
                {
                    // add the revoked certs
                    foreach (var revokedCertificate in revokedCertificates)
                    {
                        var revoked = revokedCertificate.Revoked?.Date ?? thisUpdate;
                        crlGen.AddCrlEntry(new BigInteger(1, revokedCertificate.SerialNumber),
                                           revoked, CrlReason.PrivilegeWithdrawn);
                    }
                }
                crlGen.AddExtension(X509Extensions.AuthorityKeyIdentifier, false,
                                    new AuthorityKeyIdentifierStructure(bcCertCA));

                // set new serial number
                var crlSerialNumber = BigInteger.ValueOf(DateTime.UtcNow.ToFileTimeUtc());
                crlGen.AddExtension(X509Extensions.CrlNumber, false,
                                    new CrlNumber(crlSerialNumber));

                // generate updated CRL
                var signatureGenerator = _signer.CreateX509SignatureGenerator(
                    issuer.KeyHandle, signature);
                var signatureFactory = new SignatureFactory(signature, signatureGenerator);
                var updatedCrl       = crlGen.Generate(signatureFactory);
                return(Task.FromResult(CrlEx.ToCrl(updatedCrl.GetEncoded())));
            }
            catch (Exception ex) {
                return(Task.FromException <Crl>(ex));
            }
        }
Esempio n. 6
0
 /// <summary>
 /// This must be called prior to using the other class methods, or else they will throw a null reference exception.
 /// </summary>
 /// <param name="SignatureFactoryKey">A key you have previously generated and saved by calling `new SignatureFactory()` and retrieving its private key.</param>
 internal static void Initialize(string SignatureFactoryKey)
 {
     sigFactory = new SignatureFactory(SignatureFactoryKey);
 }