Skip to content

Commit 2cd97f5

Browse files
authored
feat: working keygen (#14)
1 parent 2bb361f commit 2cd97f5

3 files changed

Lines changed: 14752 additions & 14723 deletions

File tree

components/modalViews/GenerateKeyView.tsx

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { ThemedText } from "@/components/ThemedText";
22
import isMobile from "@/constants/isMobile";
3+
import { selectUser } from "@/core/slices/authSlice";
34
import { addKey } from "@/core/slices/sshSlice";
45
import { useState } from "react";
56
import { Pressable, StyleSheet } from "react-native";
6-
import { useDispatch } from "react-redux";
7-
import { generateKeyPair } from "web-ssh-keygen";
7+
import { useDispatch, useSelector } from "react-redux";
8+
import { generateKeyPair } from "ssh-keygen-rn";
89
import { NiceDropdown } from "../NiceDropdown";
910
import { ThemedTextInput } from "../ThemedTextInput";
1011
interface GenerateKeyViewProps {
@@ -14,6 +15,8 @@ export function GenerateKeyView({ setModalVisible }: GenerateKeyViewProps) {
1415
const [selectedSize, setSelectedSize] = useState(0);
1516
const [selectedHash, setSelectedHash] = useState(0);
1617
const [name, setName] = useState("");
18+
const [passphrase, setPassphrase] = useState("");
19+
const auth = useSelector(selectUser);
1720
const dispatch = useDispatch();
1821
const possibleHashes = [
1922
{ label: "SHA-1", value: "SHA-1" },
@@ -27,13 +30,7 @@ export function GenerateKeyView({ setModalVisible }: GenerateKeyViewProps) {
2730
{ label: "4096", value: 4096 },
2831
];
2932
const generate = async () => {
30-
const keys = await generateKeyPair({
31-
alg: "RSASSA-PKCS1-v1_5",
32-
size: selectedSize as 1024 | 2048 | 4096,
33-
// @ts-expect-error fix types
34-
hash: selectedHash as "SHA-1" | "SHA-256" | "SHA-384" | "SHA-512",
35-
name: name,
36-
});
33+
const keys = await generateKeyPair(selectedSize, passphrase);
3734
console.log("Key generated", keys);
3835
dispatch(addKey({ name: name, publicKey: keys.publicKey, privateKey: keys.privateKey, id: "hi" }));
3936
setModalVisible(false);
@@ -55,6 +52,16 @@ export function GenerateKeyView({ setModalVisible }: GenerateKeyViewProps) {
5552
Size
5653
</ThemedText>
5754
<NiceDropdown setValue={setSelectedSize} value={selectedSize} data={possibleSizes} />
55+
<ThemedText style={styles.modalText} type="defaultSemiBold">
56+
Passphrase
57+
</ThemedText>
58+
<ThemedTextInput
59+
placeholder="*******"
60+
placeholderTextColor="gray"
61+
secureTextEntry
62+
value={passphrase}
63+
onChangeText={setPassphrase}
64+
/>
5865
<Pressable style={[styles.button, styles.buttonClose]} onPress={() => generate()}>
5966
<ThemedText style={styles.textStyle}>Save</ThemedText>
6067
</Pressable>

0 commit comments

Comments
 (0)