Beispiel #1
0
func postAuth(session *api.Session, keyRing *openpgp.KeyRing) {
	pub := session.User.PublicKeys["primary"]
	if pub == nil {
		fmt.Println("No public key for this account.")
		os.Exit(1)
	}

	fmt.Printf("Fingerprint: %s\n", pub.Fingerprint)
	signer := keyRing.Entity(pub.Fingerprint)
	if signer == nil {
		fmt.Println("No private key for this account.")
		os.Exit(1)
	}

	/*
	   	var signature = `-----BEGIN PGP MESSAGE-----
	   Version: Keybase Go client (OpenPGP version 0.1.0)

	   xA0DAAIB7k+6hRB9rTcBrQFRYgBTPJCXeyJib2R5Ijp7ImtleSI6eyJmaW5nZXJw
	   cmludCI6IjNiMGM0ZGU3ZDE2NThkMWE1ZmFlYzEyMGVlNGZiYTg1MTA3ZGFkMzci
	   LCJob3N0Ijoia2V5YmFzZS5pbyIsImtleV9pZCI6IjAxMDEwYjA0YTFmNzk2M2Nm
	   YjUxNjQ0ZWUyM2E0YTA2NmY1MzkxN2FmNzE1N2E5Njg5MWViYjAzNTExZTU1Yjk2
	   MmUzMGEiLCJ1aWQiOiI5NGVmMWUzNTc4OWM2ZmE2NThiNzhlMWIwNWVlZGUwMCIs
	   InVzZXJuYW1lIjoia2lzb20ifSwic3RyaW5nIjoiIiwidHlwZSI6ImF1dGgiLCJ2
	   ZXJzaW9uIjoxfSwiY3RpbWUiOjEzOTY0NzgwOTQsImV4cGlyZXNfaW4iOjg2NDAw
	   LCJ0YWciOiJzaWduYXR1cmUifcLBXAQAAQIAEAUCUzyQlwkQ7k+6hRB9rTcAANSz
	   EAAseFDy8srABjWmQqp4uhaOPGUDzO9E2wYWm6GcFf60KeenMkYUCssHoP12a4eB
	   ZLgt2ERkIFAQmn+hQkkfBSK7tQjh6XQmXstHwkhUp2XG2/Kn3Lek7t2sgaqzdt46
	   /qVmgymBbSgraW0JYzDC+Bta8RRfYhkYyNTjtWnx9Ue2r2R6UcTDGyTS4cWMgAVY
	   h1ZgQwNLfHMDqjEP93gPj9n8JZb5EN0MXGCe3Z6wMfXIams2QQ4TdsMGvwJffKel
	   GGOaqUYoTlE01zSF9RA53xTzqwC7PpVcOO6V7FMpRM6UQE6x1MQzy/Iz8gBZONpb
	   G24IkbpFj+SQYdUJ3fedTUiTWT32n/9sgp3NKY4lFdYKEDhv6fMgSLFkMhbvf6YC
	   d0Jd1OORtzke3MxJPDHRLlnCNdNA3ZfwD1Dx2Mu8j7JknWBdUsZK2KtDh3hijfmY
	   TGT1TL6fBT9DAzGfJj305rTNaYR2GnD8ncmqMCD5O+ePVFaQxyrC9zgy50UEOTNS
	   BLVqFj1mCE38ziBxO39Y1Kx4U0ZUmQ90Fz7nzhw3alnPQaPF6M8f+q2Mx+xuZhHF
	   hYddlV4afpsHp14sAeLaImLZ+IPvL+KH0f3Pc0N9rSaCJhsR5yLLpoPXk3RXrs+1
	   kXBuzD8AyhGVVJ+VCOuauUwRQT+Ergl7auG94uQi7SN15w==
	   =gRI/
	   -----END PGP MESSAGE-----`
	*/
	sigData, err := session.SignaturePostAuthData()
	if err != nil {
		fmt.Printf("Failed to get signature post auth data: %v\n", err)
		os.Exit(1)
	}

	signature, err := keyRing.Sign(sigData, pub.Fingerprint)
	if err != nil {
		fmt.Printf("Signing failed: %v\n", err)
		os.Exit(1)
	}

	authToken, err := session.SignaturePostAuth([]byte(signature))
	if err != nil {
		fmt.Printf("Posting signature authentication failed: %v\n", err)
		os.Exit(1)
	}

	fmt.Printf("Authentication token: %x\n", authToken)
}
Beispiel #2
0
func authTwitter(session *api.Session, keyRing *openpgp.KeyRing) {
	username, err := readPrompt("Twitter username: "******"Couldn't read from console: %v\n", err)
	}

	authData, err := session.TwitterGetAuth(username)
	if err != nil {
		fmt.Printf("Couldn't get authentication data: %v\n", err)
	}

	pub := session.User.PublicKeys["primary"]
	if pub == nil {
		fmt.Println("No public key for this account.")
		os.Exit(1)
	}

	fmt.Printf("Fingerprint: %s\n", pub.Fingerprint)
	signer := keyRing.Entity(pub.Fingerprint)
	if signer == nil {
		fmt.Println("No private key for this account.")
		os.Exit(1)
	}
	ioutil.WriteFile("/tmp/authdata.json", authData, 0644)
	sig, err := keyRing.Sign(authData, pub.Fingerprint)
	if err != nil {
		fmt.Printf("Couldn't sign authentication data: %v\n", err)
		os.Exit(1)
	}

	proof, err := session.ServicePostAuth(sig, username, "twitter")
	if err != nil {
		fmt.Printf("Couldn't authenticate via Twitter: %v\n", err)
		os.Exit(1)
	}
	fmt.Printf("Proof text: '%s'\n", proof.Text)
}