Skip to content
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

Token authentication support for upload #70

Merged
merged 2 commits into from
Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,7 @@ public static String lamei18n(JsonNode n) {
if (n == null)
return "";
if (n.size() > 0) {
Map<String, Object> langs = mapper.convertValue(n, new TypeReference<>() {
});
Map<String, Object> langs = mapper.convertValue(n, new TypeReference<Map<String, Object>>() {});
Map.Entry<String, Object> first = langs.entrySet().iterator().next();
return langs.getOrDefault(Locale.getDefault().getLanguage(), langs.getOrDefault("en", first.getValue())).toString();
} else {
Expand Down
4 changes: 2 additions & 2 deletions library/src/main/java/com/fidesmo/fdsm/FidesmoCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public static Optional<FidesmoCard> detect(Map<HexBytes, byte[]> commands) {
.filter(FidesmoCard::check)
.flatMap(a -> fetchTag(0x45, a));

cin = pv3cin.or(() -> pv2cin).orElse(null);
cin = pv3cin.orElseGet(() -> pv2cin.orElse(null));

cplc = response(commands, getCPLC).filter(FidesmoCard::check).map(a -> {
byte[] data = a.getData();
Expand All @@ -240,7 +240,7 @@ public static Optional<FidesmoCard> detect(Map<HexBytes, byte[]> commands) {
.map(FidesmoCard::fixup)
.flatMap(a -> fetchTag(0x42, a));

batch = pv3batch.or(() -> pv2batch).orElse(null);
batch = pv3batch.orElseGet(() -> pv2batch.orElse(null));

if (cin == null || batch == null)
return Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ abstract class CommandLineInterface {
final static protected OptionSpec<String> OPT_CREATE = parser.accepts("create", "Applet instance AID").withRequiredArg().describedAs("AID");
final static protected OptionSpec<String> OPT_UNINSTALL = parser.accepts("uninstall", "Uninstall CAP from card").withRequiredArg().describedAs("CAP file / AID");

final static protected OptionSpec<String> OPT_APP_ID = parser.accepts("app-id", "Application identifier")
.requiredIf(OPT_STORE_DATA, OPT_SECURE_APDU, OPT_UNINSTALL, OPT_INSTALL, OPT_UPLOAD, OPT_CLEANUP)
.withRequiredArg().describedAs("appId");
final static protected OptionSpec<Integer> OPT_QA = parser.accepts("qa", "Run a QA support session").withOptionalArg().ofType(Integer.class).describedAs("QA number");

final static protected OptionSpec<Integer> OPT_TIMEOUT = parser.accepts("timeout", "Timeout for services").withRequiredArg().ofType(Integer.class).describedAs("minutes");
Expand Down
12 changes: 6 additions & 6 deletions tool/src/main/java/com/fidesmo/fdsm/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -371,11 +371,7 @@ public static void main(String[] argv) {
} else {
success("No applications");
}
} else if (requiresAuthentication()) { // XXX
if (!auth.getUsername().isPresent()) {
throw new IllegalArgumentException("Application ID is required. Use --auth or FIDESMO_AUTH with appId:appKey format");
}

} else if (requiresAuthentication()) {
AuthenticatedFidesmoApiClient authenticatedClient = getAuthenticatedClient();
FormHandler formHandler = getCommandLineFormHandler();

Expand Down Expand Up @@ -641,7 +637,11 @@ private static AuthenticatedFidesmoApiClient getAuthenticatedClient() {
}

private static String getAppId() {
return auth.getUsername().orElseThrow(() -> new IllegalArgumentException("Operation requires appId authentication with appKey!"));
if (args.valueOf(OPT_APP_ID) == null) {
throw new IllegalArgumentException("Operation requires app-id parameter!");
} else {
return args.valueOf(OPT_APP_ID).toString();
}
}

private static class FidesmoService {
Expand Down