Skip to content

Commit

Permalink
pongasoft#58: proof of concept for key generation
Browse files Browse the repository at this point in the history
  • Loading branch information
ypujante committed May 24, 2013
1 parent cb18189 commit ac346b9
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 0 deletions.
25 changes: 25 additions & 0 deletions packaging/org.pongasoft.glu.packaging-setup-impl/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (c) 2013 Yan Pujante
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/

apply plugin: 'groovy'
apply plugin: 'org.linkedin.release'

dependencies {
compile spec.external.groovy

testCompile spec.external.utilsMiscGroovy
testCompile spec.external.junit
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright (c) 2013 Yan Pujante
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/

package org.pongasoft.glu.packaging.setup

import java.nio.file.Files
import java.nio.file.Path

/**
* The purpose of this class is to generate keys and keystore for glu
*
* @author yan@pongasoft.com */
public class KeysGenerator
{
Path outputFolder
char[] masterPassword

def opts =
[
keyalg: 'RSA',
keysize: 2048,
validity: 2000,
dname: [
cn: 'glu-cn',
ou: 'glu-ou',
o: 'glu-o',
c: 'glu-c'
],
]

Path generateAgentKeystore()
{
if(!Files.exists(outputFolder))
Files.createDirectories(outputFolder)

Path agentKeystore = outputFolder.resolve('agent.keystore').toAbsolutePath()

def agentKeystorePassword = "agentKeystorePassword"
def agentKeyPassword = "agentKeyPassword"

def cmd = [
'keytool',
'-noprompt',
'-genkey',
'-alias', 'agent',
'-keystore', agentKeystore.toString(),
'-storepass', agentKeystorePassword,
'-keypass', agentKeyPassword,
'-keyalg', opts.keyalg,
'-keysize', opts.keysize,
'-validity', opts.validity,
'-dname', opts.dname.collect {k, v -> "${k}=${v}"}.join(', ')
]

def process = cmd.execute()
Thread.start {
System.err << process.errorStream
}
println process.text

return agentKeystore
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2013 Yan Pujante
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/

package test.setup

import org.linkedin.groovy.util.io.fs.FileSystem
import org.linkedin.groovy.util.io.fs.FileSystemImpl
import org.pongasoft.glu.packaging.setup.KeysGenerator

/**
* @author yan@pongasoft.com */
public class TestKeysGenerator extends GroovyTestCase
{
public void testKeysGenerator()
{
FileSystemImpl.createTempFileSystem { FileSystem fs ->

def generator = new KeysGenerator(outputFolder: fs.toResource('/keys').getFile().toPath(),
masterPassword: "abcdefgh".toCharArray())

println generator.generateAgentKeystore()
}
}
}
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ include ':agent:org.linkedin.glu.agent-api',
':docs:manual',
':orchestration:org.linkedin.glu.orchestration-engine',
':provisioner:org.linkedin.glu.provisioner-core',
':packaging:org.pongasoft.glu.packaging-setup-impl',
':packaging:org.linkedin.glu.packaging-setup',
':packaging:org.linkedin.glu.packaging-all',
':scripts:org.linkedin.glu.script-jetty',
Expand Down

0 comments on commit ac346b9

Please sign in to comment.