-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add signer to support signing windows artifacts (#2156)
* Add signer for windows distribution and implement the jenkins libarary to be capable of signing for windows. Signed-off-by: Zelin Hao <[email protected]> * Replace platform with MagicMock for testing Signed-off-by: Zelin Hao <[email protected]> * Change to not initiate signer for mock case Signed-off-by: Zelin Hao <[email protected]> * Change the default signature type to .asc for compatibility with old usage Signed-off-by: Zelin Hao <[email protected]> * Add signer abstract class Signed-off-by: Zelin Hao <[email protected]> * Remove abstract method Signed-off-by: Zelin Hao <[email protected]> * Commit test cases Signed-off-by: Zelin Hao <[email protected]> * Fix python tests Signed-off-by: Zelin Hao <[email protected]> * Remove unused library import Signed-off-by: Zelin Hao <[email protected]> * Fix mock repo tests Signed-off-by: Zelin Hao <[email protected]> * Remove commmented block Signed-off-by: Zelin Hao <[email protected]> * Fix the python tests and combine credentials Signed-off-by: Zelin Hao <[email protected]> * Change path for windows tests Signed-off-by: Zelin Hao <[email protected]>
- Loading branch information
Showing
27 changed files
with
658 additions
and
397 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
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,51 @@ | ||
#!/usr/bin/env python | ||
|
||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# The OpenSearch Contributors require contributions made to | ||
# this file be licensed under the Apache-2.0 license or a | ||
# compatible open source license. | ||
|
||
import os | ||
from pathlib import Path | ||
|
||
from sign_workflow.signer import Signer | ||
|
||
""" | ||
This class is responsible for signing an artifact using the OpenSearch-signer-client and verifying its signature. | ||
The signed artifacts will be found in the same location as the original artifacts. | ||
""" | ||
|
||
|
||
class SignerPGP(Signer): | ||
|
||
ACCEPTED_FILE_TYPES = [".zip", ".jar", ".war", ".pom", ".module", ".tar.gz", ".whl", ".crate", ".rpm"] | ||
|
||
def generate_signature_and_verify(self, artifact: str, basepath: Path, signature_type: str) -> None: | ||
location = os.path.join(basepath, artifact) | ||
self.sign(artifact, basepath, signature_type) | ||
self.verify(location + signature_type) | ||
|
||
def is_valid_file_type(self, file_name: str) -> bool: | ||
return any( | ||
file_name.endswith(x) for x in SignerPGP.ACCEPTED_FILE_TYPES | ||
) | ||
|
||
def sign(self, artifact: str, basepath: Path, signature_type: str) -> None: | ||
filename = os.path.join(basepath, artifact) | ||
signature_file = filename + signature_type | ||
self.__remove_existing_signature__(signature_file) | ||
signing_cmd = [ | ||
"./opensearch-signer-client", | ||
"-i", | ||
filename, | ||
"-o", | ||
signature_file, | ||
"-p", | ||
"pgp", | ||
] | ||
self.git_repo.execute(" ".join(signing_cmd)) | ||
|
||
def verify(self, filename: str) -> None: | ||
verify_cmd = ["gpg", "--verify-files", filename] | ||
self.git_repo.execute(" ".join(verify_cmd)) |
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,51 @@ | ||
#!/usr/bin/env python | ||
|
||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# The OpenSearch Contributors require contributions made to | ||
# this file be licensed under the Apache-2.0 license or a | ||
# compatible open source license. | ||
|
||
import os | ||
from pathlib import Path | ||
|
||
from sign_workflow.signer import Signer | ||
|
||
""" | ||
This class is responsible for signing an artifact using the OpenSearch-signer-client and verifying its signature. | ||
The signed artifacts will be found in the subfolder called signed under the origin location as the original artifacts. | ||
""" | ||
|
||
|
||
class SignerWindows(Signer): | ||
|
||
ACCEPTED_FILE_TYPES = [".msi", ".exe", ".dll", ".sys", ".ps1", ".psm1", ".psd1", ".cat", ".zip"] | ||
|
||
def generate_signature_and_verify(self, artifact: str, basepath: Path, signature_type: str) -> None: | ||
self.sign(artifact, basepath, signature_type) | ||
|
||
def is_valid_file_type(self, file_name: str) -> bool: | ||
return any( | ||
file_name.endswith(x) for x in SignerWindows.ACCEPTED_FILE_TYPES | ||
) | ||
|
||
def sign(self, artifact: str, basepath: Path, signature_type: str) -> None: | ||
filename = os.path.join(basepath, artifact) | ||
signed_prefix = "signed_" | ||
signature_file = os.path.join(basepath, signed_prefix + artifact) | ||
self.__remove_existing_signature__(signature_file) | ||
signing_cmd = [ | ||
"./opensearch-signer-client", | ||
"-i", | ||
filename, | ||
"-o", | ||
signature_file, | ||
"-p", | ||
"windows", | ||
] | ||
self.git_repo.execute(" ".join(signing_cmd)) | ||
signed_folder = os.path.join(basepath, "signed") | ||
if not os.path.exists(signed_folder): | ||
os.mkdir(signed_folder) | ||
signed_location = os.path.join(signed_folder, artifact) | ||
os.rename(signature_file, signed_location) |
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,31 @@ | ||
#!/usr/bin/env python | ||
|
||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# The OpenSearch Contributors require contributions made to | ||
# this file be licensed under the Apache-2.0 license or a | ||
# compatible open source license. | ||
|
||
|
||
from sign_workflow.signer import Signer | ||
from sign_workflow.signer_pgp import SignerPGP | ||
from sign_workflow.signer_windows import SignerWindows | ||
|
||
|
||
class Signers: | ||
TYPES = { | ||
"windows": SignerWindows, | ||
"linux": SignerPGP, | ||
} | ||
|
||
@classmethod | ||
def from_platform(cls, platform: str) -> Signer: | ||
klass = cls.TYPES.get(platform, None) | ||
if not klass: | ||
raise ValueError(f"Unsupported type of platform for signing: {platform}") | ||
return klass # type: ignore[return-value] | ||
|
||
@classmethod | ||
def create(cls, platform: str) -> Signer: | ||
klass = cls.from_platform(platform) | ||
return klass() # type: ignore[no-any-return, operator] |
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
Oops, something went wrong.