New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Patched to allow "./cjdroute --import {privkey} > cjdroute.conf" to gene... #18
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,7 +101,49 @@ static int genAddress(uint8_t addressOut[40], | |
} | ||
} | ||
|
||
static int genconf() | ||
static int genAddressFromPrivKey(uint8_t addressOut[40], | ||
uint8_t privateKeyHexOut[65], | ||
uint8_t publicKeyBase32Out[53], | ||
char* privateKeyChar) | ||
{ | ||
struct Address address; | ||
uint8_t privateKey[32]; | ||
uint8_t chosenPrivateKeyHex[65]; | ||
for(int i = 0; i < 64; i++){ | ||
char c = privateKeyChar[i]; | ||
if (c >= '0' && c <= '9'){ | ||
chosenPrivateKeyHex[i] = atoi(&c); | ||
} | ||
else{ | ||
chosenPrivateKeyHex[i] = (int)c-(int)'a'+10; | ||
} | ||
} | ||
printf("\n"); | ||
//Hex_decode(privateKey, 32, chosenPrivateKeyHex, 64); | ||
int high; | ||
int low; | ||
for (int i = 0; i < 64; i+=2){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 4 spaces not 8 |
||
high = chosenPrivateKeyHex[i]; | ||
low = chosenPrivateKeyHex[i+1]; | ||
privateKey[i/2] = (high + low < 31) ? (high << 4) | low : -1; | ||
} | ||
|
||
crypto_scalarmult_curve25519_base(address.key, privateKey); | ||
AddressCalc_addressForPublicKey(address.ip6.bytes, address.key); | ||
|
||
if (address.ip6.bytes[0] == 0xFC) { | ||
Hex_encode(privateKeyHexOut, 65, privateKey, 32); | ||
Base32_encode(publicKeyBase32Out, 53, address.key, 32); | ||
Address_printIp(addressOut, &address); | ||
return 0; | ||
} | ||
|
||
fprintf(stderr, "Invalid private key passed to --import.\n"); | ||
exit(-1); | ||
} | ||
|
||
|
||
static int genconf(bool havePrivKey, char* presetPrivKey) | ||
{ | ||
uint8_t passwdBin[16]; | ||
randombytes(passwdBin, 16); | ||
|
@@ -113,7 +155,10 @@ static int genconf() | |
uint8_t publicKeyBase32[53]; | ||
uint8_t address[40]; | ||
uint8_t privateKeyHex[65]; | ||
genAddress(address, privateKeyHex, publicKeyBase32); | ||
if(havePrivKey) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. brackets after if statements |
||
genAddressFromPrivKey(address, privateKeyHex, publicKeyBase32, presetPrivKey); | ||
else | ||
genAddress(address, privateKeyHex, publicKeyBase32); | ||
|
||
printf("{\n" | ||
" // Private key:\n" | ||
|
@@ -605,7 +650,7 @@ int main(int argc, char** argv) | |
#endif | ||
Crypto_init(); | ||
assert(argc > 0); | ||
|
||
if (argc == 1) { // no arguments | ||
if (isatty(STDIN_FILENO)) { | ||
// We were started from a terminal | ||
|
@@ -621,21 +666,27 @@ int main(int argc, char** argv) | |
if (strcmp(argv[1], "--help") == 0) { | ||
return usage(argv[0]); | ||
} else if (strcmp(argv[1], "--genconf") == 0) { | ||
return genconf(); | ||
return genconf(0, ""); | ||
} else if (strcmp(argv[1], "--getcmds") == 0) { | ||
// Performed after reading the configuration | ||
} else { | ||
fprintf(stderr, "%s: unrecognized option '%s'\n", argv[0], argv[1]); | ||
fprintf(stderr, "Try `%s --help' for more information.\n", argv[0]); | ||
fprintf(stderr, "Try `%s --help' for more information.\n", argv[0]); | ||
return -1; | ||
} | ||
} | ||
if (argc > 2) { // more than one argument? | ||
fprintf(stderr, "%s: too many arguments\n", argv[0]); | ||
fprintf(stderr, "Try `%s --help' for more information.\n", argv[0]); | ||
return -1; | ||
if (strcmp(argv[1], "--import") == 0){ | ||
//argv[2] is char[] | ||
return genconf(1, argv[2]); | ||
//printf("%s\n", argv[2]); | ||
} else { | ||
fprintf(stderr, "%s: too many arguments\n", argv[0]); | ||
fprintf(stderr, "Try `%s --help' for more information.\n", argv[0]); | ||
return -1; | ||
} | ||
} | ||
|
||
struct Context context; | ||
memset(&context, 0, sizeof(struct Context)); | ||
context.base = event_base_new(); | ||
|
@@ -739,4 +790,4 @@ int main(int argc, char** argv) | |
security(Dict_getList(&config, BSTR("security")), context.logger, context.eHandler); | ||
|
||
event_base_loop(context.base, 0); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check Hex_decode() defined in util/Hex.h