mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-10 15:35:59 +01:00
(refs #115)Use registered public key for authentication
This commit is contained in:
@@ -7,26 +7,22 @@ import java.security.PublicKey
|
|||||||
import org.apache.commons.codec.binary.Base64
|
import org.apache.commons.codec.binary.Base64
|
||||||
import org.apache.sshd.common.util.Buffer
|
import org.apache.sshd.common.util.Buffer
|
||||||
import org.eclipse.jgit.lib.Constants
|
import org.eclipse.jgit.lib.Constants
|
||||||
|
import service.SshKeyService
|
||||||
|
import servlet.Database
|
||||||
|
import javax.servlet.ServletContext
|
||||||
|
|
||||||
|
class PublicKeyAuthenticator(context: ServletContext) extends PublickeyAuthenticator with SshKeyService {
|
||||||
object DummyData {
|
|
||||||
val userPublicKeys = List(
|
|
||||||
"ssh-rsa AAB3NzaC1yc2EAAAADAQABAAABAQDRzuX0WtSLzCY45nEhfFDPXzYGmvQdqnOgOUY4yGL5io/2ztyUvJdhWowkyakeoPxVk/jIP7Tu8Are5TuSD+fJp7aUbZW2CYOEsxo8cwndh/ezIX6RFjlu+xvKvZ8G7BtFLlLCcnza9uB+uEAyPH5HvGQLdV7dXctLfFqXPTr1p1RjSI7Noubm+vN4n9108rILd32MlhQiToXjL4HKWWwmppaln6bEsonOQW4/GieRjQeyWDkbVekIofnedjWl4+W0kAA+WosNwRFShgsaJLfU964HT/cGjK5auqOG+nATY0suECnxAK+5Wb6jXXYNmKiIMHypeXG1Qy2wMyMB1Gq9 tanacasino-local",
|
|
||||||
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDRzuX0WtSLzCY45nEhfFDPXzYGmvQdqnOgOUY4yGL5io/2ztyUvJdhWowkyakeoPxVk/jIP7Tu8Are5TuSD+fJp7aUbZW2CYOEsxo8cwndh/ezIX6RFjlu+xvKvZ8G7BtFLlLCcnza9uB+uEAyPH5HvGQLdV7dXctLfFqXPTr1p1RjSI7Noubm+vN4n9108rILd32MlhQiToXjL4HKWWwmppaln6bEsonOQW4/GieRjQeyWDkbVekIofnedjWl4+W0kAA+WosNwRFShgsaJLfU964HT/cGjK5auqOG+nATY0suECnxAK+5Wb6jXXYNmKiIMHypeXG1Qy2wMyMB1Gq9 tanacasino-local",
|
|
||||||
"ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEAxBEtdwpE5PaClaEq2WY369einovW2ZUOXFKndY4z8RN7S3H4G1whMJVIsj2lrw1k+ranzNmOEHFoRKO0/XIE/2mSaGOawKG76vKEA/q7A0Zw8hMcdIBPaqMhrb/K7KyJiJtcvARelO76mUGv9ucA6DqvsuPjGalqhdp9eSq+1VE= naoki@your-4v4sjfo73c"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class PublicKeyAuthenticator extends PublickeyAuthenticator {
|
|
||||||
private val logger = LoggerFactory.getLogger(classOf[PublicKeyAuthenticator])
|
private val logger = LoggerFactory.getLogger(classOf[PublicKeyAuthenticator])
|
||||||
|
|
||||||
override def authenticate(username: String, key: PublicKey, session: ServerSession): Boolean = {
|
override def authenticate(username: String, key: PublicKey, session: ServerSession): Boolean = {
|
||||||
// TODO userPublicKeys is read from DB and Users register this public key string list on Account Profile view
|
Database(context) withTransaction {
|
||||||
DummyData.userPublicKeys.exists(str => str2PublicKey(str) match {
|
getPublicKeys(username).exists { sshKey =>
|
||||||
|
str2PublicKey(sshKey.publicKey) match {
|
||||||
case Some(publicKey) => key.equals(publicKey)
|
case Some(publicKey) => key.equals(publicKey)
|
||||||
case _ => false
|
case _ => false
|
||||||
})
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private def str2PublicKey(key: String): Option[PublicKey] = {
|
private def str2PublicKey(key: String): Option[PublicKey] = {
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ object SshServer {
|
|||||||
private def configure(context: ServletContext) = {
|
private def configure(context: ServletContext) = {
|
||||||
server.setPort(DEFAULT_PORT) // TODO read from config
|
server.setPort(DEFAULT_PORT) // TODO read from config
|
||||||
server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(s"${Directory.GitBucketHome}/gitbucket.ser"))
|
server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(s"${Directory.GitBucketHome}/gitbucket.ser"))
|
||||||
server.setPublickeyAuthenticator(new PublicKeyAuthenticator)
|
server.setPublickeyAuthenticator(new PublicKeyAuthenticator(context))
|
||||||
server.setCommandFactory(new GitCommandFactory(context))
|
server.setCommandFactory(new GitCommandFactory(context))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user