-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add keygen tools * move keygen test to integration tests
- Loading branch information
Showing
7 changed files
with
219 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
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,28 @@ | ||
#!/usr/bin/env bash | ||
|
||
. tests/_integration/utils.sh | ||
|
||
test_keygen () { | ||
rm --force key key.pub test_key test_key.pub | ||
bash -c "$1 $2" | ||
check_result_zero | ||
stat key > /dev/null | ||
check_result_zero | ||
stat key.pub > /dev/null | ||
check_result_zero | ||
|
||
bash -c "$1 $2 test_key test_key.pub" | ||
check_result_zero | ||
stat test_key > /dev/null | ||
check_result_zero | ||
stat test_key.pub > /dev/null | ||
check_result_zero | ||
} | ||
|
||
test_keygen python tools/python/keygen.py | ||
test_keygen node tools/js/keygen.js | ||
test_keygen "php -f" tools/php/keygen.php | ||
test_keygen ruby tools/ruby/keygen.rb | ||
test_keygen "go run" tools/go/keygen.go | ||
|
||
exit ${status} |
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,39 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/cossacklabs/themis/gothemis/keys" | ||
"io/ioutil" | ||
"os" | ||
) | ||
|
||
func main() { | ||
args_count := len(os.Args) | ||
|
||
if args_count != 1 && args_count != 3 { | ||
fmt.Printf("Usage: go %s <private_key_path> <public_key_path>\n", os.Args[0]) | ||
os.Exit(1) | ||
} | ||
|
||
var private_key_path, public_key_path string | ||
if args_count == 1 { | ||
private_key_path = "key" | ||
public_key_path = "key.pub" | ||
} else if args_count == 3 { | ||
private_key_path = os.Args[1] | ||
public_key_path = os.Args[2] | ||
} | ||
|
||
keypair, err := keys.New(keys.KEYTYPE_EC) | ||
if err != nil { | ||
panic(err) | ||
} | ||
err = ioutil.WriteFile(private_key_path, keypair.Private.Value, 0400) | ||
if err != nil { | ||
panic(err) | ||
} | ||
err = ioutil.WriteFile(public_key_path, keypair.Public.Value, 0666) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} |
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,20 @@ | ||
const jsthemis = require('jsthemis'); | ||
const fs = require('fs'); | ||
|
||
if (process.argv.length !== 2 && process.argv.length !== 4) { | ||
console.log('Usage: node keygen.js <private_key_path> <public_key_path>'); | ||
process.exit(1); | ||
} | ||
|
||
if (process.argv.length === 2) { | ||
var private_key_path = 'key'; | ||
var public_key_path = 'key.pub'; | ||
} else if (process.argv.length === 4){ | ||
var private_key_path = process.argv[2]; | ||
var public_key_path = process.argv[3]; | ||
} | ||
|
||
keypair = new jsthemis.KeyPair(); | ||
|
||
fs.writeFileSync(private_key_path, keypair.private(), {'mode': 0o400}); | ||
fs.writeFileSync(public_key_path, keypair.public()); |
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,40 @@ | ||
<?php | ||
# | ||
# Copyright (c) 2015 Cossack Labs Limited | ||
# | ||
# 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. | ||
# | ||
|
||
|
||
if (!extension_loaded('phpthemis')) die("no phpthemis extention found!\n"); | ||
|
||
if (count($argv) != 1 && count($argv) != 3) { | ||
die("Usage: php -f keygen.php <private_key_path> <public_key_path>\n"); | ||
} | ||
$private_key_path = null; | ||
$public_key_path = null; | ||
if (count($argv) == 1){ | ||
$private_key_path = "key"; | ||
$public_key_path = "key.pub"; | ||
} else if (count($argv) == 3){ | ||
$private_key_path = $argv[1]; | ||
$public_key_path = $argv[2]; | ||
} | ||
|
||
$keypair = phpthemis_gen_ec_key_pair(); | ||
|
||
file_put_contents($private_key_path, $keypair['private_key']); | ||
chmod($private_key_path, 0400); | ||
file_put_contents($public_key_path, $keypair['public_key']); | ||
|
||
?> |
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,44 @@ | ||
# | ||
# Copyright (c) 2015 Cossack Labs Limited | ||
# | ||
# 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 sys | ||
import os | ||
from pythemis.skeygen import KEY_PAIR_TYPE, GenerateKeyPair | ||
|
||
args_count = len(sys.argv) | ||
if args_count != 3 and args_count != 1: | ||
print("Usage: python {} <private_key_path> <public_key_path>".format( | ||
os.path.basename(__file__))) | ||
exit(1) | ||
|
||
keypair = GenerateKeyPair(KEY_PAIR_TYPE.EC) | ||
private_key = keypair.export_private_key() | ||
public_key = keypair.export_public_key() | ||
if args_count == 1: | ||
private_key_path = 'key' | ||
public_key_path = 'key.pub' | ||
elif args_count == 3: | ||
private_key_path = sys.argv[1] | ||
public_key_path = sys.argv[2] | ||
|
||
|
||
with open(private_key_path, "wb") as private_key_file: | ||
private_key_file.write(private_key) | ||
|
||
os.chmod(private_key_path, 0o400) | ||
|
||
with open(public_key_path, "wb") as public_key_file: | ||
public_key_file.write(public_key) |
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,47 @@ | ||
# | ||
# Copyright (c) 2015 Cossack Labs Limited | ||
# | ||
# 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. | ||
# | ||
|
||
#!/usr/bin/env ruby | ||
|
||
require 'fileutils' | ||
require 'rubygems' | ||
require 'rubythemis' | ||
|
||
if ARGV.length != 0 && ARGV.length != 2 | ||
puts "Usage: ruby keygen.rb <private_key_path> <public_key_path>" | ||
exit 1 | ||
end | ||
|
||
generator = Themis::SKeyPairGen.new | ||
|
||
if ARGV.length == 0 | ||
private_key_path = 'key' | ||
public_key_path = 'key.pub' | ||
elsif ARGV.length == 2 | ||
private_key_path = ARGV[0] | ||
public_key_path = ARGV[1] | ||
end | ||
keypair = generator.ec | ||
|
||
File.open(private_key_path, 'w') { |file| | ||
file.write(keypair[0]) | ||
} | ||
|
||
FileUtils.chmod 0400, private_key_path | ||
|
||
File.open(public_key_path, 'w') { |file| | ||
file.write(keypair[1]) | ||
} |