forked from notaryproject/notation
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Junjie Gao <[email protected]>
- Loading branch information
Showing
15 changed files
with
496 additions
and
43 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
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
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
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
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,43 @@ | ||
// Copyright The Notary Project Authors. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package utils | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
) | ||
|
||
// CRLRevoke sends http post request to http://localhost:8080/revoke | ||
func CRLRevoke() error { | ||
url := "http://localhost:10086/revoke" | ||
resp, err := http.Post(url, "application/json", nil) | ||
if err != nil { | ||
return err | ||
} | ||
defer resp.Body.Close() | ||
fmt.Printf("CRL revoked with status code: %d\n", resp.StatusCode) | ||
return nil | ||
} | ||
|
||
// CRLUnrevoke sends http post request to http://localhost:8080/unrevoke | ||
func CRLUnrevoke() error { | ||
url := "http://localhost:10086/unrevoke" | ||
resp, err := http.Post(url, "application/json", nil) | ||
if err != nil { | ||
return err | ||
} | ||
defer resp.Body.Close() | ||
fmt.Printf("CRL unrevoked with status code: %d\n", resp.StatusCode) | ||
return nil | ||
} |
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
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
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 @@ | ||
# Copyright The Notary Project Authors. | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import http.server | ||
import socketserver | ||
import os | ||
|
||
PORT = 10086 | ||
DATA_DIR = './testdata/config/crl' | ||
revoke_flag = False | ||
|
||
|
||
class CRLRequestHandler(http.server.SimpleHTTPRequestHandler): | ||
def do_GET(self): | ||
global revoke_flag | ||
if self.path == '/leaf.crl': | ||
file_name = 'leaf_revoked.crl' if revoke_flag else 'leaf.crl' | ||
file_path = os.path.join(DATA_DIR, file_name) | ||
print("crl path", file_path) | ||
if os.path.exists(file_path): | ||
self.send_response(200) | ||
self.send_header('Content-Type', 'application/pkix-crl') | ||
self.end_headers() | ||
with open(file_path, 'rb') as f: | ||
self.wfile.write(f.read()) | ||
else: | ||
self.send_error(404, 'File Not Found') | ||
else: | ||
self.send_error(404, 'Not Found') | ||
def do_POST(self): | ||
global revoke_flag | ||
if self.path == '/revoke': | ||
revoke_flag = True | ||
self.send_response(201) | ||
self.end_headers() | ||
self.wfile.write(b'ok') | ||
elif self.path == '/unrevoke': | ||
revoke_flag = False | ||
self.send_response(201) | ||
self.end_headers() | ||
self.wfile.write(b'ok') | ||
else: | ||
self.send_error(404, 'Not Found') | ||
|
||
class ReusableTCPServer(socketserver.TCPServer): | ||
allow_reuse_address = True | ||
|
||
with ReusableTCPServer(('', PORT), CRLRequestHandler) as httpd: | ||
print(f"Serving at port {PORT}") | ||
try: | ||
httpd.serve_forever() | ||
finally: | ||
httpd.server_close() |
Oops, something went wrong.