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
7ad9c4bd
Commit
7ad9c4bd
authored
7 years ago
by
deuce
Browse files
Options
Downloads
Patches
Plain Diff
Move stuff from letsyncrypt.js to http.js
Parsing the response code and headers is an HTTP thing, not an ACME thing.
parent
29063c8b
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
exec/load/acmev2.js
+12
-22
12 additions, 22 deletions
exec/load/acmev2.js
exec/load/http.js
+12
-1
12 additions, 1 deletion
exec/load/http.js
with
24 additions
and
23 deletions
exec/load/acmev2.js
+
12
−
22
View file @
7ad9c4bd
...
...
@@ -78,7 +78,7 @@ ACMEv2.prototype.get_directory = function()
{
if
(
this
.
directory
===
undefined
)
{
var
ret
=
this
.
ua
.
Get
(
"
https://
"
+
this
.
host
+
this
.
dir_path
);
if
(
this
.
get_
response_code
()
!=
200
)
if
(
this
.
ua
.
response_code
!=
200
)
throw
(
"
Error fetching directory
"
);
this
.
store_headers
(
true
);
this
.
directory
=
JSON
.
parse
(
ret
);
...
...
@@ -94,7 +94,7 @@ ACMEv2.prototype.create_new_account = function(opts)
{
var
ret
=
this
.
post
(
'
newAccount
'
,
opts
);
if
(
this
.
get_
response_code
()
!=
201
)
if
(
this
.
ua
.
response_code
!=
201
)
throw
(
"
newAccount did not return a 201 status!
"
);
if
(
this
.
last_headers
[
'
Location
'
]
===
undefined
)
...
...
@@ -110,9 +110,9 @@ ACMEv2.prototype.create_new_order = function(opts)
if
(
opts
.
identifiers
===
undefined
)
throw
(
"
create_new_order() requires an identifier in opts
"
);
ret
=
JSON
.
parse
(
this
.
post
(
'
newOrder
'
,
opts
));
if
(
this
.
get_
response_code
()
!=
201
)
{
if
(
this
.
ua
.
response_code
!=
201
)
{
log
(
LOG_DEBUG
,
JSON
.
stringify
(
ret
));
throw
(
"
newOrder responded with
"
+
this
.
get_
response_code
()
+
"
not 201
"
);
throw
(
"
newOrder responded with
"
+
this
.
ua
.
response_code
+
"
not 201
"
);
}
if
(
this
.
last_headers
[
'
Location
'
]
===
undefined
)
...
...
@@ -126,7 +126,7 @@ ACMEv2.prototype.accept_challenge = function(challenge)
{
var
opts
=
{
keyAuthorization
:
challenge
.
token
+
"
.
"
+
this
.
thumbprint
()};
var
ret
=
this
.
post_url
(
challenge
.
url
,
opts
)
if
(
this
.
get_
response_code
()
!=
200
)
if
(
this
.
ua
.
response_code
!=
200
)
throw
(
"
accept_challenge did not return 200
"
);
return
JSON
.
parse
(
ret
);
}
...
...
@@ -135,7 +135,7 @@ ACMEv2.prototype.poll_authorization = function(auth)
{
var
ret
=
JSON
.
parse
(
this
.
ua
.
Get
(
auth
));
if
(
this
.
get_
response_code
()
!=
200
)
if
(
this
.
ua
.
response_code
!=
200
)
return
false
;
this
.
store_headers
(
true
);
...
...
@@ -159,7 +159,7 @@ ACMEv2.prototype.finalize_order = function(order, csr)
opts
.
csr
=
this
.
base64url
(
csr
.
export
(
CryptCert
.
FORMAT
.
CERTIFICATE
));
var
ret
=
this
.
post_url
(
order
.
finalize
,
opts
)
if
(
this
.
get_
response_code
()
!=
200
)
if
(
this
.
ua
.
response_code
!=
200
)
throw
(
"
finalize_order did not return 200
"
);
return
JSON
.
parse
(
ret
);
...
...
@@ -171,7 +171,7 @@ ACMEv2.prototype.poll_order = function(order)
if
(
loc
===
undefined
)
throw
(
"
No order location!
"
);
var
ret
=
this
.
ua
.
Get
(
loc
)
if
(
this
.
get_
response_code
()
!=
200
)
if
(
this
.
ua
.
response_code
!=
200
)
throw
(
"
order poll did not return 200
"
);
this
.
store_headers
(
true
);
...
...
@@ -185,7 +185,7 @@ ACMEv2.prototype.get_cert = function(order)
if
(
order
.
certificate
===
undefined
)
throw
(
"
Order has no certificate!
"
);
var
cert
=
this
.
ua
.
Get
(
order
.
certificate
);
if
(
this
.
get_
response_code
()
!=
200
)
if
(
this
.
ua
.
response_code
!=
200
)
throw
(
"
get_cert request did not return 200
"
);
this
.
store_headers
(
true
);
return
new
CryptCert
(
cert
);
...
...
@@ -222,7 +222,7 @@ ACMEv2.prototype.get_authorization = function(url)
{
var
ret
=
this
.
ua
.
Get
(
url
);
if
(
this
.
get_
response_code
()
!=
200
)
if
(
this
.
ua
.
response_code
!=
200
)
throw
(
"
get_authorization request did not return 200
"
);
this
.
store_headers
(
true
);
...
...
@@ -272,21 +272,12 @@ ACMEv2.prototype.get_response_code = function()
return
parseInt
(
m
[
1
],
10
);
}
// TODO: Should this be in http.js?
ACMEv2
.
prototype
.
store_headers
=
function
(
update_nonce
)
{
var
h
=
{}
;
var
h
=
this
.
ua
.
response_headers_parsed
;
if
(
update_nonce
===
undefined
)
update_nonce
=
false
;
for
(
i
in
this
.
ua
.
response_headers
)
{
m
=
this
.
ua
.
response_headers
[
i
].
match
(
/^
(
.*
?)
:
\s
*
(
.*
?)\s
*$/
);
if
(
m
)
{
if
(
h
[
m
[
1
]]
==
undefined
)
h
[
m
[
1
]]
=
[];
h
[
m
[
1
]].
push
(
m
[
2
]);
}
}
if
(
h
[
'
Replay-Nonce
'
]
!==
undefined
)
{
if
(
update_nonce
)
this
.
last_nonce
=
h
[
'
Replay-Nonce
'
][
0
];
...
...
@@ -339,9 +330,8 @@ ACMEv2.prototype.post_url = function(url, data, post_method)
body
=
body
.
replace
(
/:{/g
,
'
: {
'
);
body
=
body
.
replace
(
/,"/g
,
'
, "
'
);
ret
=
this
.
ua
.
Post
(
url
,
body
);
var
resp
=
this
.
get_response_code
();
/* We leave error handling to the caller */
if
(
resp
==
200
||
resp
==
201
)
if
(
this
.
ua
.
response_code
==
200
||
this
.
ua
.
response_code
==
201
)
this
.
store_headers
(
true
);
return
ret
;
}
This diff is collapsed.
Click to expand it.
exec/load/http.js
+
12
−
1
View file @
7ad9c4bd
...
...
@@ -19,7 +19,7 @@ function HTTPRequest(username,password,extra_headers)
this
.
base
;
this
.
url
;
this
.
body
;
this
.
username
=
username
;
this
.
password
=
password
;
...
...
@@ -130,12 +130,17 @@ function HTTPRequest(username,password,extra_headers)
this
.
status_line
=
this
.
sock
.
recvline
(
4096
);
if
(
this
.
status_line
==
null
)
throw
(
"
Unable to read status
"
);
var
m
=
this
.
status_line
.
match
(
/^HTTP
\/[
0-9
]
+
\.[
0-9
]
+
([
0-9
]{3})
/
);
if
(
m
===
null
)
throw
(
"
Unable to parse status line '
"
+
this
.
status_line
+
"
'
"
);
this
.
response_code
=
parseInt
(
m
[
1
],
10
);
};
this
.
ReadHeaders
=
function
()
{
var
header
=
''
;
var
m
;
this
.
response_headers
=
[];
this
.
response_headers_parsed
=
{};
for
(;;)
{
header
=
this
.
sock
.
recvline
(
4096
,
120
);
...
...
@@ -147,6 +152,12 @@ function HTTPRequest(username,password,extra_headers)
m
=
header
.
match
(
/^Content-length:
\s
+
([
0-9
]
+
)
$/i
);
if
(
m
!=
null
)
this
.
contentlength
=
parseInt
(
m
[
1
]);
m
=
header
.
match
(
/^
(
.*
?)
:
\s
*
(
.*
?)\s
*$/
);
if
(
m
)
{
if
(
this
.
response_headers_parsed
[
m
[
1
]]
==
undefined
)
this
.
response_headers_parsed
[
m
[
1
]]
=
[];
this
.
response_headers_parsed
[
m
[
1
]].
push
(
m
[
2
]);
}
}
};
...
...
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