Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Synchronet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Main
Synchronet
Commits
cda515a6
Commit
cda515a6
authored
7 years ago
by
deuce
Browse files
Options
Downloads
Patches
Plain Diff
More cleanup.
parent
b4694cb5
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
exec/load/acmev2.js
+40
-31
40 additions, 31 deletions
exec/load/acmev2.js
with
40 additions
and
31 deletions
exec/load/acmev2.js
+
40
−
31
View file @
cda515a6
...
@@ -46,19 +46,17 @@ function ACMEv2(opts)
...
@@ -46,19 +46,17 @@ function ACMEv2(opts)
this
.
key_id
=
opts
.
key_id
;
this
.
key_id
=
opts
.
key_id
;
if
(
opts
.
host
!==
undefined
)
if
(
opts
.
host
!==
undefined
)
this
.
host
=
opts
.
host
;
this
.
host
=
opts
.
host
;
this
.
jws_format
=
'
sha256
'
;
this
.
ua
=
new
HTTPRequest
();
this
.
ua
=
new
HTTPRequest
();
if
(
this
.
key_id
===
undefined
)
{
try
{
try
{
this
.
get_key_id
();
this
.
get_key_id
();
}
catch
(
e
)
{}
}
}
catch
(
e
)
{}
}
}
ACMEv2
.
prototype
.
get_key_id
=
function
()
ACMEv2
.
prototype
.
get_key_id
=
function
()
{
{
this
.
create_new_account
({
termsOfServiceAgreed
:
true
,
onlyReturnExisting
:
true
});
if
(
this
.
key_id
===
undefined
)
return
(
this
.
create_new_account
({
onlyReturnExisting
:
true
}));
}
}
ACMEv2
.
prototype
.
host
=
"
acme-staging-v02.api.letsencrypt.org
"
;
ACMEv2
.
prototype
.
host
=
"
acme-staging-v02.api.letsencrypt.org
"
;
...
@@ -80,7 +78,7 @@ ACMEv2.prototype.get_directory = function()
...
@@ -80,7 +78,7 @@ ACMEv2.prototype.get_directory = function()
var
ret
=
this
.
ua
.
Get
(
"
https://
"
+
this
.
host
+
this
.
dir_path
);
var
ret
=
this
.
ua
.
Get
(
"
https://
"
+
this
.
host
+
this
.
dir_path
);
if
(
this
.
ua
.
response_code
!=
200
)
if
(
this
.
ua
.
response_code
!=
200
)
throw
(
"
Error fetching directory
"
);
throw
(
"
Error fetching directory
"
);
this
.
store_headers
(
true
);
this
.
update_nonce
(
);
this
.
directory
=
JSON
.
parse
(
ret
);
this
.
directory
=
JSON
.
parse
(
ret
);
}
}
return
this
.
directory
;
return
this
.
directory
;
...
@@ -94,15 +92,30 @@ ACMEv2.prototype.create_new_account = function(opts)
...
@@ -94,15 +92,30 @@ ACMEv2.prototype.create_new_account = function(opts)
{
{
var
ret
=
this
.
post
(
'
newAccount
'
,
opts
);
var
ret
=
this
.
post
(
'
newAccount
'
,
opts
);
if
(
this
.
ua
.
response_code
!=
201
)
if
(
this
.
ua
.
response_code
!=
201
&&
this
.
ua
.
response_code
!=
200
)
throw
(
"
newAccount
did not return a
201 status!
"
);
throw
(
"
newAccount
returned
"
+
this
.
ua
.
response_code
+
"
, not a 200 or
201 status!
"
);
if
(
this
.
last_headers
[
'
Location
'
]
===
undefined
)
if
(
this
.
ua
.
response_headers_parsed
[
'
Location
'
]
===
undefined
)
throw
(
"
No Location header in 201 response.
"
);
throw
(
"
No Location header in newAccount response.
"
);
this
.
key_id
=
this
.
last_headers
[
'
Location
'
][
0
];
this
.
key_id
=
this
.
ua
.
response_headers_parsed
[
'
Location
'
][
0
];
return
JSON
.
parse
(
ret
);
}
ACMEv2
.
prototype
.
update_account
=
function
(
opts
)
{
this
.
get_key_id
();
var
ret
=
this
.
post_url
(
this
.
key_id
,
opts
);
if
(
this
.
ua
.
response_code
!=
201
&&
this
.
ua
.
response_code
!=
200
)
throw
(
"
update_account returned
"
+
this
.
ua
.
response_code
+
"
, not a 200 or 201 status!
"
);
return
JSON
.
parse
(
ret
);
return
JSON
.
parse
(
ret
);
}
}
ACMEv2
.
prototype
.
get_account
=
function
()
{
return
this
.
update_account
({});
}
ACMEv2
.
prototype
.
create_new_order
=
function
(
opts
)
ACMEv2
.
prototype
.
create_new_order
=
function
(
opts
)
{
{
var
ret
;
var
ret
;
...
@@ -115,9 +128,9 @@ ACMEv2.prototype.create_new_order = function(opts)
...
@@ -115,9 +128,9 @@ ACMEv2.prototype.create_new_order = function(opts)
throw
(
"
newOrder responded with
"
+
this
.
ua
.
response_code
+
"
not 201
"
);
throw
(
"
newOrder responded with
"
+
this
.
ua
.
response_code
+
"
not 201
"
);
}
}
if
(
this
.
last
_headers
[
'
Location
'
]
===
undefined
)
if
(
this
.
ua
.
response
_headers
_parsed
[
'
Location
'
]
===
undefined
)
throw
(
"
No Location header in 201 response.
"
);
throw
(
"
No Location header in 201 response.
"
);
ret
.
Location
=
this
.
last
_headers
.
Location
[
0
];
ret
.
Location
=
this
.
ua
.
response
_headers
_parsed
.
Location
[
0
];
return
ret
;
return
ret
;
}
}
...
@@ -137,7 +150,7 @@ ACMEv2.prototype.poll_authorization = function(auth)
...
@@ -137,7 +150,7 @@ ACMEv2.prototype.poll_authorization = function(auth)
if
(
this
.
ua
.
response_code
!=
200
)
if
(
this
.
ua
.
response_code
!=
200
)
return
false
;
return
false
;
this
.
store_headers
(
true
);
this
.
update_nonce
(
);
for
(
var
challenge
in
ret
.
challenges
)
{
for
(
var
challenge
in
ret
.
challenges
)
{
if
(
ret
.
challenges
[
challenge
].
status
==
'
valid
'
)
if
(
ret
.
challenges
[
challenge
].
status
==
'
valid
'
)
...
@@ -173,7 +186,7 @@ ACMEv2.prototype.poll_order = function(order)
...
@@ -173,7 +186,7 @@ ACMEv2.prototype.poll_order = function(order)
var
ret
=
this
.
ua
.
Get
(
loc
)
var
ret
=
this
.
ua
.
Get
(
loc
)
if
(
this
.
ua
.
response_code
!=
200
)
if
(
this
.
ua
.
response_code
!=
200
)
throw
(
"
order poll did not return 200
"
);
throw
(
"
order poll did not return 200
"
);
this
.
store_headers
(
true
);
this
.
update_nonce
(
);
ret
=
JSON
.
parse
(
ret
);
ret
=
JSON
.
parse
(
ret
);
ret
.
Location
=
loc
;
ret
.
Location
=
loc
;
...
@@ -187,7 +200,7 @@ ACMEv2.prototype.get_cert = function(order)
...
@@ -187,7 +200,7 @@ ACMEv2.prototype.get_cert = function(order)
var
cert
=
this
.
ua
.
Get
(
order
.
certificate
);
var
cert
=
this
.
ua
.
Get
(
order
.
certificate
);
if
(
this
.
ua
.
response_code
!=
200
)
if
(
this
.
ua
.
response_code
!=
200
)
throw
(
"
get_cert request did not return 200
"
);
throw
(
"
get_cert request did not return 200
"
);
this
.
store_headers
(
true
);
this
.
update_nonce
(
);
return
new
CryptCert
(
cert
);
return
new
CryptCert
(
cert
);
}
}
...
@@ -224,7 +237,7 @@ ACMEv2.prototype.get_authorization = function(url)
...
@@ -224,7 +237,7 @@ ACMEv2.prototype.get_authorization = function(url)
if
(
this
.
ua
.
response_code
!=
200
)
if
(
this
.
ua
.
response_code
!=
200
)
throw
(
"
get_authorization request did not return 200
"
);
throw
(
"
get_authorization request did not return 200
"
);
this
.
store_headers
(
true
);
this
.
update_nonce
(
);
return
JSON
.
parse
(
ret
);
return
JSON
.
parse
(
ret
);
}
}
...
@@ -261,7 +274,6 @@ ACMEv2.prototype.hash_thing = function(data)
...
@@ -261,7 +274,6 @@ ACMEv2.prototype.hash_thing = function(data)
return
this
.
key
.
decrypt
(
D
);
return
this
.
key
.
decrypt
(
D
);
}
}
// TODO: Should this be in http.js?
ACMEv2
.
prototype
.
get_response_code
=
function
()
ACMEv2
.
prototype
.
get_response_code
=
function
()
{
{
if
(
this
.
ua
.
status_line
===
undefined
)
if
(
this
.
ua
.
status_line
===
undefined
)
...
@@ -272,17 +284,10 @@ ACMEv2.prototype.get_response_code = function()
...
@@ -272,17 +284,10 @@ ACMEv2.prototype.get_response_code = function()
return
parseInt
(
m
[
1
],
10
);
return
parseInt
(
m
[
1
],
10
);
}
}
ACMEv2
.
prototype
.
store_headers
=
function
(
update_nonce
)
ACMEv2
.
prototype
.
update_nonce
=
function
(
)
{
{
var
h
=
this
.
ua
.
response_headers_parsed
;
if
(
this
.
ua
.
response_headers_parsed
[
'
Replay-Nonce
'
]
!==
undefined
)
this
.
last_nonce
=
this
.
ua
.
response_headers_parsed
[
'
Replay-Nonce
'
][
0
];
if
(
update_nonce
===
undefined
)
update_nonce
=
false
;
if
(
h
[
'
Replay-Nonce
'
]
!==
undefined
)
{
if
(
update_nonce
)
this
.
last_nonce
=
h
[
'
Replay-Nonce
'
][
0
];
}
this
.
last_headers
=
h
;
}
}
ACMEv2
.
prototype
.
thumbprint
=
function
()
ACMEv2
.
prototype
.
thumbprint
=
function
()
...
@@ -332,6 +337,10 @@ ACMEv2.prototype.post_url = function(url, data, post_method)
...
@@ -332,6 +337,10 @@ ACMEv2.prototype.post_url = function(url, data, post_method)
ret
=
this
.
ua
.
Post
(
url
,
body
);
ret
=
this
.
ua
.
Post
(
url
,
body
);
/* We leave error handling to the caller */
/* We leave error handling to the caller */
if
(
this
.
ua
.
response_code
==
200
||
this
.
ua
.
response_code
==
201
)
if
(
this
.
ua
.
response_code
==
200
||
this
.
ua
.
response_code
==
201
)
this
.
store_headers
(
true
);
this
.
update_nonce
(
);
return
ret
;
return
ret
;
}
}
// TODO: keyChange
// TODO: revokeCert
// TODO: Deactivate an Authorization
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment