Comments (3)
The code in https://github.com/Yubico/yubihsm-shell/blob/master/lib/lib_util.c#L156 uses 0
as third argument to strtoul
which means prepending 0x and 0 to a number automatically means it is parsed as hex or octal.
I agree it is not so obvious since it not documented (nor tested in the unit tests).
Simple solution is to just change the last argument in this instance to 10, i.e.:
-- a/lib/lib_util.c
+++ b/lib/lib_util.c
@@ -153,7 +153,7 @@ bool parse_usb_url(const char *url, unsigned long *serial) {
str += strlen("serial=");
errno = 0;
- *serial = strtoul(str, &endptr, 0);
+ *serial = strtoul(str, &endptr, 10);
if ((errno == ERANGE && *serial == ULONG_MAX) || endptr == str ||
(errno != 0 && *serial == 0)) {
*serial = 0;
..which leads to the behavior you expected:
$ ./src/yubihsm-shell -C yhusb://serial=0004242424
yubihsm> debug all
Debug messages enabled
yubihsm> connect
[LIB - INF 12:49:45.418410] yubihsm.c:4069 (yh_init_connector): Loading usb backend
[LIB - INF 12:49:45.430295] lib_util.c:166 (parse_usb_url): USB url parsed with serial 4242424.
I do not have a strong opinion here as it does not have any clear security implications but it feels natural that it should be documented and be reflected in the unit test (lib/tests/test_usb_url.c
).
from yubihsm-shell.
@nevun: as you mention in the linked commit, it is theoretically possible that some scripts or other usage of the CLI tool are based on the hex/octal behaviour. I assume it is a rarely used edge case and wasn't documented as such.
The new variant is more friendly to users, so I would personally prefer it, but understand if the old behaviour is kept for compatibility reasons.
from yubihsm-shell.
I'm OK with the change, but I think that at that point it's worth returning false from that function, at least in the 0x
case.
I believe the behavior now is quite surprising in that instance: as shown in the test if a serial number of 0x1234
is given the function will succeed but set serial
to 0
, i.e., match any serial number. Sure it will print a debug message but that's probably not enough if the function doesn't fail.
The octal case is a bit trickier since a leading zero doesn't make strtoul
fail. Maybe it's worth adding the word decimal
somewhere on line 166?
from yubihsm-shell.
Related Issues (20)
- Signing keys need updating on website HOT 2
- Unwrapping an exported wrapped key without device involvement HOT 4
- Remote problem HOT 1
- the last changelog entry references wrong version HOT 1
- RFE: is it possible to start making github releases?🤔
- Changelog typo HOT 1
- Unable to import an asymmetric wrapping key? HOT 6
- Cannot generate RSA-OAEP key pair? HOT 3
- Error running keytool on windows with YubiHSM HOT 11
- AES CTR Encryption HOT 3
- Failed to store symmetric key: Invalid command HOT 4
- yubihsm-shell ignores env var YUBIHSM_PKCS11_CONF HOT 2
- "debug" option in config file explodes the shell HOT 5
- Yubihsm ran out of session after a while when using with pkcs11 module HOT 10
- Malformed data error when signing SHA3-384 with yh_util_sign_pkcs1v1_5 HOT 1
- 2.4.2: test suite fails in 12% units HOT 7
- Docker container cannot connect to yubihsm connector running on host on Ubuntu 22.04.3 LTS HOT 1
- Inquiry about YubiHSM 2 Authentication & Access control HOT 1
- Support for SHA3-* HOT 1
- [P11 - ERR 21:10:53.246143] util_pkcs11.c:4593 (parse_rsa_generate_template): Boolean truth check failed for attribute 0x1 [P11 - ERR 21:10:53.246154] yubihsm_pkcs11.c:5248 (C_GenerateKeyPair): Unable to parse generation template HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from yubihsm-shell.