mirror of
				https://github.com/pinpox/pgp2ssh.git
				synced 2025-11-04 08:39:16 +01:00 
			
		
		
		
	fix cast
This commit is contained in:
		
							parent
							
								
									a48ca25841
								
							
						
					
					
						commit
						698f59df42
					
				
					 1 changed files with 11 additions and 28 deletions
				
			
		
							
								
								
									
										39
									
								
								main.go
									
										
									
									
									
								
							
							
						
						
									
										39
									
								
								main.go
									
										
									
									
									
								
							| 
						 | 
					@ -1,7 +1,6 @@
 | 
				
			||||||
package main
 | 
					package main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	// "bytes"
 | 
					 | 
				
			||||||
	"crypto/sha512"
 | 
						"crypto/sha512"
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"log"
 | 
						"log"
 | 
				
			||||||
| 
						 | 
					@ -11,19 +10,19 @@ import (
 | 
				
			||||||
	"github.com/ProtonMail/go-crypto/openpgp/armor"
 | 
						"github.com/ProtonMail/go-crypto/openpgp/armor"
 | 
				
			||||||
	"github.com/ProtonMail/go-crypto/openpgp/eddsa"
 | 
						"github.com/ProtonMail/go-crypto/openpgp/eddsa"
 | 
				
			||||||
	"github.com/ProtonMail/go-crypto/openpgp/packet"
 | 
						"github.com/ProtonMail/go-crypto/openpgp/packet"
 | 
				
			||||||
	 "github.com/davecgh/go-spew/spew"
 | 
					 | 
				
			||||||
	"golang.org/x/crypto/ssh"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"crypto/ed25519"
 | 
						"crypto/ed25519"
 | 
				
			||||||
	"errors"
 | 
						"errors"
 | 
				
			||||||
	"reflect"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// "filippo.io/edwards25519"
 | 
					 | 
				
			||||||
	"github.com/Mic92/ssh-to-age/bech32"
 | 
						"github.com/Mic92/ssh-to-age/bech32"
 | 
				
			||||||
	"golang.org/x/crypto/curve25519"
 | 
						"golang.org/x/crypto/curve25519"
 | 
				
			||||||
 | 
						// "github.com/davecgh/go-spew/spew"
 | 
				
			||||||
 | 
						// "bytes"
 | 
				
			||||||
 | 
						// "golang.org/x/crypto/ssh"
 | 
				
			||||||
	// "golang.org/x/crypto/curve25519"
 | 
						// "golang.org/x/crypto/curve25519"
 | 
				
			||||||
 | 
						// "reflect"
 | 
				
			||||||
 | 
						// "filippo.io/edwards25519"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func readEntity(keypath string) (*openpgp.Entity, error) {
 | 
					func readEntity(keypath string) (*openpgp.Entity, error) {
 | 
				
			||||||
| 
						 | 
					@ -55,26 +54,9 @@ func ed25519PrivateKeyToCurve25519(pk ed25519.PrivateKey) ([]byte, error) {
 | 
				
			||||||
	return out[:curve25519.ScalarSize], nil
 | 
						return out[:curve25519.ScalarSize], nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func SSHPrivateKeyToAge(sshKey, passphrase []byte) (*string, error) {
 | 
					func SSHPrivateKeyToAge(privatekey ed25519.PrivateKey, passphrase []byte) (*string, error) {
 | 
				
			||||||
	var (
 | 
					 | 
				
			||||||
		privateKey interface{}
 | 
					 | 
				
			||||||
		err        error
 | 
					 | 
				
			||||||
	)
 | 
					 | 
				
			||||||
	if len(passphrase) > 0 {
 | 
					 | 
				
			||||||
		privateKey, err = ssh.ParseRawPrivateKeyWithPassphrase(sshKey, passphrase)
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		privateKey, err = ssh.ParseRawPrivateKey(sshKey)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return nil, fmt.Errorf("failed to parse ssh private key: %w", err)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ed25519Key, ok := privateKey.(*ed25519.PrivateKey)
 | 
						bytes, err := ed25519PrivateKeyToCurve25519(privatekey)
 | 
				
			||||||
	if !ok {
 | 
					 | 
				
			||||||
		return nil, fmt.Errorf("got %s key type but: %w", reflect.TypeOf(privateKey), UnsupportedKeyType)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	bytes, err := ed25519PrivateKeyToCurve25519(*ed25519Key) //THIS
 | 
					 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -94,19 +76,20 @@ func main() {
 | 
				
			||||||
		log.Fatal(err)
 | 
							log.Fatal(err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	log.Println(reflect.TypeOf(e.PrivateKey.PrivateKey))
 | 
						// log.Println(reflect.TypeOf(e.PrivateKey.PrivateKey))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	castkey, ok := e.PrivateKey.PrivateKey.(*eddsa.PrivateKey)
 | 
						castkey, ok := e.PrivateKey.PrivateKey.(*eddsa.PrivateKey)
 | 
				
			||||||
	if !ok {
 | 
						if !ok {
 | 
				
			||||||
		log.Fatal("failed to cast")
 | 
							log.Fatal("failed to cast")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	spew.Dump(castkey)
 | 
						// spew.Dump(castkey)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// TODO: Not sure if these are the correct bytes ??????
 | 
				
			||||||
	agekey, err := SSHPrivateKeyToAge(castkey.D, []byte{})
 | 
						agekey, err := SSHPrivateKeyToAge(castkey.D, []byte{})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		log.Fatal(err)
 | 
							log.Fatal(err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	log.Println(agekey)
 | 
						fmt.Println(*agekey)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue