Good rsa key ?
This commit is contained in:
parent
3c7aa052dc
commit
2d1c67fc65
1 changed files with 16 additions and 2 deletions
|
@ -6,11 +6,13 @@ import java.io.BufferedWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.security.KeyPair;
|
import java.security.KeyPair;
|
||||||
import java.security.KeyPairGenerator;
|
import java.security.KeyPairGenerator;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.security.interfaces.RSAPublicKey;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Base64.Encoder;
|
import java.util.Base64.Encoder;
|
||||||
|
@ -124,8 +126,20 @@ public class MailConfirmation extends FormResponse {
|
||||||
post("https://git-users.peerat.dev/api/v1/admin/users/", createUser);
|
post("https://git-users.peerat.dev/api/v1/admin/users/", createUser);
|
||||||
|
|
||||||
JSONObject sendKey = new JSONObject();
|
JSONObject sendKey = new JSONObject();
|
||||||
System.out.println(new String(new byte[] {0,0,0,7})+"ssh-rsa "+new String(encoder.encode(pair.getPublic().getEncoded())));
|
RSAPublicKey pub = (RSAPublicKey) pair.getPublic();
|
||||||
sendKey.put("key", new String(new byte[] {0,0,0,7})+"ssh-rsa "+new String(encoder.encode(pair.getPublic().getEncoded())));
|
byte[] exponent = pub.getPublicExponent().toByteArray();
|
||||||
|
byte[] modulus = pub.getModulus().toByteArray();
|
||||||
|
byte[] key = new byte[19+exponent.length+modulus.length];
|
||||||
|
System.arraycopy(new byte[] {0,0,0,7,(byte)'s',(byte)'s',(byte)'h',(byte)'-',(byte)'r',(byte)'s',(byte)'a'}, 0, key, 0, 11);
|
||||||
|
byte[] exLength = ByteBuffer.allocate(4).putInt(exponent.length).array();
|
||||||
|
byte[] modLength = ByteBuffer.allocate(4).putInt(modulus.length).array();
|
||||||
|
System.arraycopy(exLength, 0, key, 11, 4);
|
||||||
|
System.arraycopy(exponent, 0, key, 14, exponent.length);
|
||||||
|
System.arraycopy(modLength, 0, key, 14+exponent.length, 4);
|
||||||
|
System.arraycopy(modulus, 0, key, 18+exponent.length, modulus.length);
|
||||||
|
|
||||||
|
System.out.println("ssh-rsa "+new String(encoder.encode(key)));
|
||||||
|
sendKey.put("key", "ssh-rsa "+new String(encoder.encode(key)));
|
||||||
sendKey.put("read_only", false);
|
sendKey.put("read_only", false);
|
||||||
sendKey.put("title", "peer_at_code_auto_push_key_"+pseudo);
|
sendKey.put("title", "peer_at_code_auto_push_key_"+pseudo);
|
||||||
post("https://git-users.peerat.dev/api/v1/admin/users/"+pseudo+"/keys", sendKey);
|
post("https://git-users.peerat.dev/api/v1/admin/users/"+pseudo+"/keys", sendKey);
|
||||||
|
|
Loading…
Add table
Reference in a new issue