Ejemplo n.º 1
0
        public async Task <CertificateStore> FinalizeAsync(PrivKey certPrivateKey, CancellationToken cancel = default)
        {
            long giveup = Time.Tick64 + CoresConfig.AcmeClientSettings.GiveupTime;

            int numRetry = 0;

            while (true)
            {
                if (giveup < Time.Tick64)
                {
                    throw new ApplicationException("ProcessAllAuthAsync: Give up.");
                }

                if (this.Info.status == AcmeOrderStatus.invalid)
                {
                    throw new ApplicationException($"Order failed. Details: \"{this.AuthzList.Select(x => x.GetChallengeErrors())._Combine(" ")._OneLine(" ")}\"");
                }
                else if (this.Info.status == AcmeOrderStatus.pending)
                {
                    await ProcessAllAuthAsync(cancel);
                    await UpdateInfoAsync(cancel);

                    giveup = Time.Tick64 + CoresConfig.AcmeClientSettings.GiveupTime;

                    continue;
                }
                else if (this.Info.status == AcmeOrderStatus.ready)
                {
                    // Create a CSR
                    Csr csr = new Csr(certPrivateKey, new CertificateOptions(certPrivateKey.Algorithm, this.Info.identifiers ![0] !.value));
Ejemplo n.º 2
0
    public static JwsPacket Encapsulate(PrivKey key, string?kid, string nonce, string url, object?payload)
    {
        JwsKey jwk = CreateJwsKey(key.PublicKey, out string algName, out string signerName);

        JwsProtected protect = new JwsProtected()
        {
            alg   = algName,
            jwk   = kid._IsEmpty() ? jwk : null,
            kid   = kid._IsEmpty() ? null : kid,
            nonce = nonce,
            url   = url,
        };

        JwsPacket ret = new JwsPacket()
        {
            Protected = protect._ObjectToJson(base64url: true, includeNull: true),
            payload   = (payload == null ? "" : payload._ObjectToJson(base64url: true)),
        };

        var signer = key.GetSigner(signerName);

        byte[] signature = signer.Sign((ret.Protected + "." + ret.payload)._GetBytes_Ascii());

        ret.signature = signature._Base64UrlEncode();

        return(ret);
    }
Ejemplo n.º 3
0
        public async Task <WebRet> DownloadAsync(WebMethods method, PrivKey key, string?kid, string url, object?request, CancellationToken cancel = default)
        {
            string nonce = await GetNonceAsync(cancel);

            //("*** " + url)._Debug();

            WebRet webret = await Web.RequestWithJwsObjectAsync(method, key, kid, nonce, url, request, cancel, Consts.MimeTypes.JoseJson);

            return(webret);
        }
Ejemplo n.º 4
0
 public Account(string screet = "")
 {
     if (screet != "")
     {
         PrivKey = new PrivateKey("secp256k1", BigInteger.Parse(screet));
     }
     else
     {
         PrivKey = new PrivateKey();
     }
     SecretNumber = PrivKey.secret;
     PubKey       = PrivKey.publicKey();
 }
Ejemplo n.º 5
0
        public async Task <AcmeAccount> LoginAccountAsync(PrivKey key, string[] contacts, CancellationToken cancel = default)
        {
            AcmeEntryPoints url = await Options.GetEntryPointsAsync(cancel);

            AcmeCreateAccountPayload req = new AcmeCreateAccountPayload()
            {
                contact = contacts,
                termsOfServiceAgreed = true,
            };

            WebUserRet <object> ret = await this.RequestAsync <object>(WebMethods.POST, key, null, url.newAccount !, req, cancel);

            string accountUrl = ret.System.Headers.GetValues("Location").Single();

            if (accountUrl._IsEmpty())
            {
                throw new ApplicationException("Account Location is empty.");
            }

            return(new AcmeAccount(EnsureInternal.Yes, this, key, accountUrl));
        }
Ejemplo n.º 6
0
        public async Task <WebUserRet <TResponse> > RequestAsync <TResponse>(WebMethods method, PrivKey key, string?kid, string url, object?request, CancellationToken cancel = default)
        {
            string nonce = await GetNonceAsync(cancel);

            //("*** " + url)._Debug();

            WebRet webret = await Web.RequestWithJwsObject(method, key, kid, nonce, url, request, cancel, Consts.MimeTypes.JoseJson);

            TResponse ret = webret.Deserialize <TResponse>(true);

            //webret.Headers._DebugHeaders();
            //webret.ToString()._Debug();

            return(webret.CreateUserRet(ret));
        }
Ejemplo n.º 7
0
 internal AcmeAccount(EnsureInternal yes, AcmeClient client, PrivKey privKey, string accountUrl)
 {
     this.Client     = client;
     this.PrivKey    = privKey;
     this.AccountUrl = accountUrl;
 }
Ejemplo n.º 8
0
 public MessageReceiver(PrivKey decodingKey, MessageConverter converter)
 {
     m_decodingKey = decodingKey;
     m_converter   = converter;
 }
Ejemplo n.º 9
0
    public virtual async Task <WebRet> RequestWithJwsObjectAsync(WebMethods method, PrivKey privKey, string?kid, string nonce, string url, object?payload, CancellationToken cancel = default, string postContentType = Consts.MimeTypes.Json)
    {
        JwsPacket reqPacket = JwsUtil.Encapsulate(privKey, kid, nonce, url, payload);

        return(await this.RequestWithJsonObjectAsync(method, url, reqPacket, cancel, postContentType));
    }