public PmlElement ValueToPml() { if (_value == null) { return(new PmlNull()); } switch (_type) { case CciResultType.Binary: return(new PmlBinary((byte[])_value)); case CciResultType.Message: case CciResultType.Object: case CciResultType.Value: case CciResultType.Error: return(new PmlString(_value.ToString())); case CciResultType.Success: return(new PmlInteger(1)); case CciResultType.List: { PmlCollection c = new PmlCollection(); foreach (Object i in (Array)_value) { c.Add(i.ToString()); } return(c); } case CciResultType.Pml: return((PmlElement)_value); default: return(new PmlString("Unknown type: " + _type.ToString())); } }
public void AuthorizeDomains(String[] domains, CreateHTTPChallengeCallback challenge_callback) { RegisterKey(); RSAParameters account_key_params = account_key.ExportParameters(false); String thumbprint; using (SHA256 sha = SHA256.Create()) thumbprint = urlbase64(sha.ComputeHash(Encoding.UTF8.GetBytes(PmlJsonWriter.EncodeMessage(new PmlDictionary() { { "e", urlbase64(account_key_params.Exponent) }, { "kty", "RSA" }, { "n", urlbase64(account_key_params.Modulus) } })))); foreach (String altname in domains) { Byte[] response_string = signed_request(acme_url + "/acme/new-authz", new PmlDictionary() { { "resource", "new-authz" }, { "identifier", new PmlDictionary() { { "type", "dns" }, { "value", altname } } } }); PmlDictionary response = (PmlDictionary)PmlJsonReader.DecodeMessage(response_string); PmlCollection challenges = (PmlCollection)response["challenges"]; PmlDictionary challenge = null; foreach (PmlDictionary item in challenges) { if ((String)item["type"] == "http-01") { challenge = item; } } String challenge_token = (String)challenge["token"]; String challenge_uri = (String)challenge["uri"]; String keyauth = challenge_token + "." + thumbprint; challenge_callback("/.well-known/acme-challenge/" + challenge_token, keyauth); try { response_string = signed_request(challenge_uri, new PmlDictionary() { { "resource", "challenge" }, { "keyAuthorization", keyauth } }); response = (PmlDictionary)PmlJsonReader.DecodeMessage(response_string); while ((String)response["status"] == "pending") { Thread.Sleep(1000); using (WebClient wc = new WebClient()) response_string = wc.DownloadData(challenge_uri); response = (PmlDictionary)PmlJsonReader.DecodeMessage(response_string); } } finally { challenge_callback("/.well-known/acme-challenge/" + challenge_token, null); } if ((String)response["status"] != "valid") { throw new InvalidOperationException("Challenge rejected for domain " + altname + " (" + response["status"] + ")"); } } }
public PmlCollection ToPml(int offset) { PmlCollection c = new PmlCollection(); for (int i = _offset + offset; i < _command.Length; i++) { c.Add(_command[i]); } return(c); }