Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Basic ACME-compatible JWS encoding * Validated RFC 7515 compatibility for JWS Flattened JSON Serialization * Starting the root ACME client interface * Validated boulder interoperability with a basic "new-reg" request
- Loading branch information
Showing
23 changed files
with
1,796 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
############################################################################### | ||
# Set default behavior to automatically normalize line endings. | ||
############################################################################### | ||
* text=auto | ||
|
||
############################################################################### | ||
# Set default behavior for command prompt diff. | ||
# | ||
# This is need for earlier builds of msysgit that does not have it on by | ||
# default for csharp files. | ||
# Note: This is only used by command line | ||
############################################################################### | ||
#*.cs diff=csharp | ||
|
||
############################################################################### | ||
# Set the merge driver for project and solution files | ||
# | ||
# Merging from the command prompt will add diff markers to the files if there | ||
# are conflicts (Merging from VS is not affected by the settings below, in VS | ||
# the diff markers are never inserted). Diff markers may cause the following | ||
# file extensions to fail to load in VS. An alternative would be to treat | ||
# these files as binary and thus will always conflict and require user | ||
# intervention with every merge. To do so, just uncomment the entries below | ||
############################################################################### | ||
#*.sln merge=binary | ||
#*.csproj merge=binary | ||
#*.vbproj merge=binary | ||
#*.vcxproj merge=binary | ||
#*.vcproj merge=binary | ||
#*.dbproj merge=binary | ||
#*.fsproj merge=binary | ||
#*.lsproj merge=binary | ||
#*.wixproj merge=binary | ||
#*.modelproj merge=binary | ||
#*.sqlproj merge=binary | ||
#*.wwaproj merge=binary | ||
|
||
############################################################################### | ||
# behavior for image files | ||
# | ||
# image files are treated as binary by default. | ||
############################################################################### | ||
#*.jpg binary | ||
#*.png binary | ||
#*.gif binary | ||
|
||
############################################################################### | ||
# diff behavior for common document formats | ||
# | ||
# Convert binary document formats to text before diffing them. This feature | ||
# is only available from the command line. Turn it on by uncommenting the | ||
# entries below. | ||
############################################################################### | ||
#*.doc diff=astextplain | ||
#*.DOC diff=astextplain | ||
#*.docx diff=astextplain | ||
#*.DOCX diff=astextplain | ||
#*.dot diff=astextplain | ||
#*.DOT diff=astextplain | ||
#*.pdf diff=astextplain | ||
#*.PDF diff=astextplain | ||
#*.rtf diff=astextplain | ||
#*.RTF diff=astextplain |
41 changes: 41 additions & 0 deletions
41
letsencrypt-win/LetsEncrypt.ACME-test/AcmeClientUnitTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace LetsEncrypt.ACME | ||
{ | ||
[TestClass] | ||
public class AcmeClientUnitTests | ||
{ | ||
Uri _rootUrl = new Uri("http://acme2.aws3.ezshield.ws:4000/"); | ||
|
||
[TestMethod] | ||
public void TestInit() | ||
{ | ||
var client = new AcmeClient(); | ||
client.RootUrl = _rootUrl; | ||
|
||
client.Init(); | ||
} | ||
|
||
[TestMethod] | ||
public void TestGetDirectory() | ||
{ | ||
var client = new AcmeClient(); | ||
client.RootUrl = _rootUrl; | ||
|
||
var acmeDir = client.GetDirectory(); | ||
} | ||
|
||
|
||
[TestMethod] | ||
public void TestRegister() | ||
{ | ||
var client = new AcmeClient(); | ||
client.RootUrl = _rootUrl; | ||
client.Register(new string[] { | ||
"mailto:letsencrypt@mailinator.com", | ||
"tel:+14109361212", | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using System; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Newtonsoft.Json; | ||
using LetsEncrypt.ACME.JOSE; | ||
using System.Net; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace LetsEncrypt.ACME | ||
{ | ||
[TestClass] | ||
public class AcmeUnitTest1 | ||
{ | ||
Uri _rootUrl = new Uri("http://acme2.aws3.ezshield.ws:4000/"); | ||
|
||
[TestMethod] | ||
public void TestNewReg() | ||
{ | ||
var requ = WebRequest.Create(_rootUrl); | ||
var resp = requ.GetResponse(); | ||
Assert.IsNotNull(resp); | ||
|
||
var nonceKey = resp.Headers.AllKeys.FirstOrDefault( | ||
x => x.Equals("Replay-nonce", StringComparison.OrdinalIgnoreCase)); | ||
Assert.IsFalse(string.IsNullOrEmpty(nonceKey)); | ||
var nonceValue = resp.Headers[nonceKey]; | ||
|
||
var newReg = new | ||
{ | ||
resource = "new-reg", | ||
contact = new string[] | ||
{ | ||
"mailto:cert-admin@example.com", | ||
"tel:+12025551212" | ||
}, | ||
}; | ||
var newRegSer = JsonConvert.SerializeObject(newReg); | ||
|
||
var algSigner = new RS256Signer(); | ||
algSigner.Init(); | ||
|
||
var unprotectedHeader = new | ||
{ | ||
alg = "RS256", | ||
jwk = algSigner.ExportJwk() | ||
}; | ||
var protectedHeader = new | ||
{ | ||
nonce = nonceValue, | ||
}; | ||
|
||
var acmeJson = JwsHelper.SignFlatJson(algSigner.Sign, newRegSer, | ||
protectedHeader, unprotectedHeader); | ||
var acmeJsonBytes = Encoding.ASCII.GetBytes(acmeJson); | ||
|
||
requ = WebRequest.Create(new Uri(_rootUrl, "/acme/new-reg")); | ||
requ.Method = "POST"; | ||
requ.ContentType = "application/json"; | ||
requ.ContentLength = acmeJsonBytes.Length; | ||
using (var s = requ.GetRequestStream()) | ||
{ | ||
s.Write(acmeJsonBytes, 0, acmeJsonBytes.Length); | ||
} | ||
resp = requ.GetResponse(); | ||
} | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
letsencrypt-win/LetsEncrypt.ACME-test/JwsHelperUnitTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using LetsEncrypt.ACME.JOSE; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace LetsEncrypt.ACME | ||
{ | ||
[TestClass] | ||
public class JwsHelperUnitTests | ||
{ | ||
[TestMethod] | ||
public void TestSignFlagJson() | ||
{ | ||
Func<byte[], byte[]> sigFunc = (x) => | ||
{ | ||
using (var rsa = new System.Security.Cryptography.RSACryptoServiceProvider()) | ||
{ | ||
rsa.ImportParameters(JwsUnitTests.GetRsaParamsForRfc7515Example_A_2_1()); | ||
using (var sha256 = new System.Security.Cryptography.SHA256CryptoServiceProvider()) | ||
{ | ||
return rsa.SignData(x, sha256); | ||
} | ||
} | ||
}; | ||
|
||
object protectedSample = new // From the RFC example | ||
{ | ||
alg = "RS256" | ||
}; | ||
object headerSample = new // From the RFC example | ||
{ | ||
kid = "2010-12-29" | ||
}; | ||
string payloadSample = // From the RFC example | ||
"{\"iss\":\"joe\",\r\n" + | ||
" \"exp\":1300819380,\r\n" + | ||
" \"http://example.com/is_root\":true}"; | ||
|
||
var wsRegex = new Regex("\\s+"); | ||
var sigExpected = // Derived from the RFC example in A.6.4 | ||
wsRegex.Replace(@"{ | ||
""payload"":""eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFtcGxlLmNvbS9pc19yb290Ijp0cnVlfQ"", | ||
""protected"":""eyJhbGciOiJSUzI1NiJ9"", | ||
""header"":{""kid"":""2010-12-29""}, | ||
""signature"": | ||
""cC4hiUPoj9Eetdgtv3hF80EGrhuB__dzERat0XF9g2VtQgr9PJbu3XOiZj5RZ | ||
mh7AAuHIm4Bh-0Qc_lF5YKt_O8W2Fp5jujGbds9uJdbF9CUAr7t1dnZcAcQjb | ||
KBYNX4BAynRFdiuB--f_nZLgrnbyTyWzO75vRK5h6xBArLIARNPvkSjtQBMHl | ||
b1L07Qe7K0GarZRmB_eSN9383LcOLn6_dO--xi12jzDwusC-eOkHWEsqtFZES | ||
c6BfI7noOPqvhJ1phCnvWh6IeYI2w9QOYEUipUTI8np6LbgGY9Fs98rqVt5AX | ||
LIhWkWywlVmtVrBp0igcN_IoypGlUPQGe77Rw"" | ||
}", ""); | ||
var sigActual = wsRegex.Replace(JwsHelper.SignFlatJson( | ||
sigFunc, payloadSample, protectedSample, headerSample), ""); | ||
Assert.AreEqual(sigExpected, sigActual); | ||
} | ||
} | ||
} |
Oops, something went wrong.