-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from cytechmobile/feature/pkAuth
feat(backend): Replace Ssh Agent with Keys Handling
- Loading branch information
Showing
16 changed files
with
153 additions
and
261 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
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
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
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
45 changes: 45 additions & 0 deletions
45
src/main/java/network/radicle/tools/github/services/AuthService.java
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,45 @@ | ||
package network.radicle.tools.github.services; | ||
|
||
import com.sshtools.common.publickey.SshKeyUtils; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Inject; | ||
import network.radicle.tools.github.Config; | ||
import network.radicle.tools.github.core.radicle.Session; | ||
import network.radicle.tools.github.utils.Multibase; | ||
import org.eclipse.microprofile.config.inject.ConfigProperty; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.File; | ||
import java.io.PrintStream; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.Optional; | ||
|
||
@ApplicationScoped | ||
public class AuthService { | ||
private static final Logger logger = LoggerFactory.getLogger(AuthService.class); | ||
|
||
@ConfigProperty(name = "rad.home") | ||
Optional<String> radHome; | ||
|
||
@Inject Config config; | ||
|
||
public String sign(Session session) { | ||
var originalError = System.err; | ||
try { | ||
System.setErr(new PrintStream(new ByteArrayOutputStream())); | ||
var kp = SshKeyUtils.getPrivateKey(new File(radHome.orElse("~/.radicle") + "/keys/radicle"), | ||
config.getRadicle().passphrase()); | ||
var dataToSign = session.id + ":" + session.publicKey; | ||
var signedData = kp.getPrivateKey().sign(dataToSign.getBytes(StandardCharsets.UTF_8)); | ||
|
||
return Multibase.encode(Multibase.Base.Base58BTC, signedData); | ||
} catch (Exception e) { | ||
logger.debug("Failed to sign the session. Error: {}", e.getMessage()); | ||
return null; | ||
} finally { | ||
System.setErr(originalError); | ||
} | ||
} | ||
} |
Oops, something went wrong.