Skip to content
This repository has been archived by the owner on Apr 3, 2022. It is now read-only.

Commit

Permalink
replaced usage of deprecated API in the signature validation code and…
Browse files Browse the repository at this point in the history
… reverted the 1.4.4 personal api key requirement
  • Loading branch information
Stekeblad committed Jun 12, 2021
1 parent 1d2414c commit 1c0eb56
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .idea/modules/videouploader.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ privacy policy can be found here:
Downloads can be found under "Releases" in the right sidebar
[or by clicking here](https://github.com/Stekeblad/Stekeblads-Video-Uploader/releases)

Note that you need Java 8 **and your own YouTube API key** to use
Stekeblads Video Uploader.
[Help on creating your own API key.](https://github.com/Stekeblad/Stekeblads-Video-Uploader/wiki/Personal-API-key)<!-- @IGNORE PREVIOUS: link -->
Note that you need Java 8 to use Stekeblads Video Uploader.

### Images
Images are taken from the 1.1 release, several things have changed since
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group 'io.github.stekeblad'
version '1.4.4'
version '1.4.5'

apply plugin: 'idea'
apply plugin: 'java'
Expand Down
36 changes: 0 additions & 36 deletions src/main/java/io/github/stekeblad/videouploader/main/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import io.github.stekeblad.videouploader.utils.AlertUtils;
import io.github.stekeblad.videouploader.utils.ConfigManager;
import io.github.stekeblad.videouploader.utils.Constants;
import io.github.stekeblad.videouploader.utils.background.OpenInBrowser;
import io.github.stekeblad.videouploader.utils.translation.TranslationBundles;
import io.github.stekeblad.videouploader.utils.translation.Translations;
import io.github.stekeblad.videouploader.utils.translation.TranslationsManager;
Expand All @@ -19,12 +18,8 @@

import java.io.IOException;
import java.lang.reflect.Field;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Locale;

import static io.github.stekeblad.videouploader.utils.Constants.AUTH_DIR;

/**
* The program starts here, opens MainWindow and waits for all windows to close
*/
Expand All @@ -50,37 +45,6 @@ public void start(Stage primaryStage) {
return;
}

try {
if (!Files.exists(Paths.get(AUTH_DIR)))
Files.createDirectories(Paths.get(AUTH_DIR));

if (!Files.exists(Paths.get(AUTH_DIR, "client_secrets.json"))) {

if (!Files.exists(Paths.get(AUTH_DIR, "place your own client_secrets.json file here")))
Files.createFile(Paths.get(AUTH_DIR, "place your own client_secrets.json file here"));

String choice = AlertUtils.threeButtons("Missing API key - Stekeblads Video Uploader",
"You need your own YouTube Data API v3 key to use " +
"Stekeblads Video Uploader. Please create one and save it to " +
Paths.get(AUTH_DIR, "client_secrets.json").toAbsolutePath().toString() +
"\r\n\r\nClick look around to try Stekeblads Video Uploader with all YouTube-related features " +
"inaccessible or read how to create a API key for free.",
"Read how",
"Look around",
"Exit");
if ("Read how".equals(choice)) {
OpenInBrowser.openInBrowser("https://github.com/Stekeblad/Stekeblads-Video-Uploader/wiki/Personal-API-key");
return;
} else if ("Exit".equals(choice))
return;
// else Look around, continue program, be prepared for exceptions
}
} catch (Exception e) {
AlertUtils.simpleClose("ERROR - Stekeblads Video Uploader",
"Failed while checking for an API key").showAndWait();
return;
}

// Set the default exception handler, hopefully it can catch some of the exceptions that is not already caught
Thread.setDefaultUncaughtExceptionHandler((thread, exception) -> AlertUtils.unhandledExceptionDialog(exception));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.google.crypto.tink.JsonKeysetReader;
import com.google.crypto.tink.KeysetHandle;
import com.google.crypto.tink.PublicKeyVerify;
import com.google.crypto.tink.config.TinkConfig;
import com.google.crypto.tink.signature.SignatureConfig;

/**
* Allows checking digital signatures using Google Tink: https://github.com/google/tink/
Expand All @@ -26,7 +26,7 @@ public class CheckSignatureWithTink {
public static boolean verifySignature(byte[] data, byte[] signature) {
try {
if (!isTinkRegistered) {
TinkConfig.register();
SignatureConfig.register();
isTinkRegistered = true;
}

Expand Down
20 changes: 17 additions & 3 deletions src/main/java/io/github/stekeblad/videouploader/youtube/Auth.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@

import java.io.*;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

import static io.github.stekeblad.videouploader.utils.Constants.AUTH_DIR;

Expand All @@ -38,9 +41,7 @@ public static Credential authUser() throws IOException {
scope.add(YouTubeScopes.YOUTUBE_UPLOAD);
scope.add(YouTubeScopes.YOUTUBE);

Reader clientSecretReader = new InputStreamReader(new FileInputStream(
new File(Paths.get(AUTH_DIR, "client_secrets.json").toUri())));
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, clientSecretReader);
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, getSecRead());
FileDataStoreFactory fileFactory = new FileDataStoreFactory(new File(AUTH_DIR));

GoogleAuthorizationCodeFlow authFlow = new GoogleAuthorizationCodeFlow.Builder(
Expand Down Expand Up @@ -89,4 +90,17 @@ public static String getChannelName() {
return null;
}
}

/**
* Gets user custom file if present, else default file
*/
public static Reader getSecRead() throws IOException {
Path userSecFile = Paths.get(AUTH_DIR, "client_secrets.json");
if (Files.exists(userSecFile, LinkOption.NOFOLLOW_LINKS)) {
return new InputStreamReader(new FileInputStream(new File(userSecFile.toUri())));
} else {
return new InputStreamReader(Objects.requireNonNull(
Auth.class.getClassLoader().getResourceAsStream(".auth/client_secrets.json")));
}
}
}

0 comments on commit 1c0eb56

Please sign in to comment.