Revision 37857
branches/v2_0_0_prep/extensions/org.gvsig.installer/org.gvsig.installer.lib/org.gvsig.installer.lib.impl/src/main/java/org/gvsig/installer/lib/impl/info/InstallerInfoFileWriter.java | ||
---|---|---|
37 | 37 |
|
38 | 38 |
import org.gvsig.installer.lib.api.PackageInfo; |
39 | 39 |
import org.gvsig.installer.lib.api.PackageInfoWriter; |
40 |
import org.gvsig.installer.lib.impl.utils.SignUtil; |
|
40 | 41 |
import org.gvsig.installer.lib.spi.InstallerInfoFileException; |
41 | 42 |
|
42 | 43 |
/** |
... | ... | |
75 | 76 |
throw new InstallerInfoFileException("install_infofile_not_found", |
76 | 77 |
e); |
77 | 78 |
} |
79 |
SignUtil signutil = new SignUtil(); |
|
80 |
if( signutil.canSign() ) { |
|
81 |
signutil.sign(file); |
|
82 |
} |
|
78 | 83 |
} |
79 | 84 |
|
80 | 85 |
/** |
branches/v2_0_0_prep/extensions/org.gvsig.installer/org.gvsig.installer.lib/org.gvsig.installer.lib.impl/src/main/java/org/gvsig/installer/lib/impl/DefaultPackageInfo.java | ||
---|---|---|
35 | 35 |
import java.util.List; |
36 | 36 |
|
37 | 37 |
import org.gvsig.installer.lib.api.Dependencies; |
38 |
import org.gvsig.installer.lib.api.PackageInfo; |
|
39 |
import org.gvsig.installer.lib.api.Version; |
|
38 |
import org.gvsig.installer.lib.api.InstallerLocator; |
|
40 | 39 |
import org.gvsig.installer.lib.api.InstallerManager.ARCH; |
41 | 40 |
import org.gvsig.installer.lib.api.InstallerManager.JVM; |
42 | 41 |
import org.gvsig.installer.lib.api.InstallerManager.OS; |
43 | 42 |
import org.gvsig.installer.lib.api.InstallerManager.STATE; |
43 |
import org.gvsig.installer.lib.api.PackageInfo; |
|
44 |
import org.gvsig.installer.lib.api.Version; |
|
44 | 45 |
import org.gvsig.installer.lib.api.execution.InstallPackageServiceException; |
45 | 46 |
import org.gvsig.installer.lib.impl.info.InstallerInfoTags; |
46 | 47 |
import org.gvsig.installer.lib.impl.utils.DeleteFile; |
47 | 48 |
import org.gvsig.installer.lib.impl.utils.Download; |
49 |
import org.gvsig.installer.lib.impl.utils.SignUtil; |
|
48 | 50 |
import org.gvsig.tools.task.SimpleTaskStatus; |
49 | 51 |
|
50 | 52 |
/** |
... | ... | |
61 | 63 |
private String antScript = null; |
62 | 64 |
private String type = "unknow"; |
63 | 65 |
private Boolean signed = false; |
66 |
private Boolean broken = false; |
|
64 | 67 |
|
65 | 68 |
private String state = STATE.DEVEL; |
66 | 69 |
private String operatingSystem = OS.ALL; |
... | ... | |
537 | 540 |
} |
538 | 541 |
|
539 | 542 |
public void checkSignature(byte[] pkgdata) { |
540 |
// TODO Auto-generated method stub |
|
541 |
|
|
543 |
this.signed = false; |
|
544 |
SignUtil signutil = null; |
|
545 |
List<byte[]> keys = InstallerLocator.getInstallerManager() |
|
546 |
.getPublicKeys(); |
|
547 |
if( keys.size()<1 ) { |
|
548 |
// No hay claves publicas, asi que no comprobamos ninguna firma |
|
549 |
// y decirmos a todos que no estan firmados. |
|
550 |
this.signed = false; |
|
551 |
return; |
|
552 |
} |
|
553 |
for (byte[] rawkey : keys) { |
|
554 |
signutil = new SignUtil(rawkey); |
|
555 |
if (signutil.canVerify()) { |
|
556 |
int status = signutil.verify(pkgdata); |
|
557 |
switch (status) { |
|
558 |
case SignUtil.SIGN_OK: |
|
559 |
// El paquete tiene una firma correcta,lo marcamos |
|
560 |
// como firmado y salimos. |
|
561 |
this.signed = true; |
|
562 |
return; |
|
563 |
case SignUtil.NOT_SIGNED: |
|
564 |
// El paquete no va firmado, lo marcamos como no |
|
565 |
// firmado y salimos. |
|
566 |
this.signed = false; |
|
567 |
return; |
|
568 |
case SignUtil.SIGN_FAIL: |
|
569 |
default: |
|
570 |
// La firma del paquete no es correcta para esta clave, |
|
571 |
// lo intentamos con el resto de claves. |
|
572 |
break; |
|
573 |
} |
|
574 |
} |
|
575 |
} |
|
576 |
// Si habiendo claves publicas la comprobacion de la firma con todas ellas |
|
577 |
// falla marcamos el paquete como roto. |
|
578 |
this.broken = true; |
|
542 | 579 |
} |
543 | 580 |
|
544 | 581 |
public boolean isBroken() { |
545 |
// TODO |
|
546 |
|
|
547 |
// if (this.isOfficial() && !this.isSigned()) { |
|
548 |
// return true; |
|
549 |
// } else { |
|
550 |
// return false; |
|
551 |
// } |
|
552 |
// else |
|
582 |
if( this.broken ) { |
|
583 |
return true; |
|
584 |
} |
|
585 |
if( this.isOfficial() && !this.isSigned() ) { |
|
586 |
return true; |
|
587 |
} |
|
553 | 588 |
return false; |
554 | 589 |
} |
555 | 590 |
|
556 | 591 |
public boolean isSigned() { |
557 |
// return this.signed; |
|
558 |
return true; |
|
592 |
return signed; |
|
559 | 593 |
} |
560 | 594 |
|
561 | 595 |
} |
branches/v2_0_0_prep/extensions/org.gvsig.installer/org.gvsig.installer.lib/org.gvsig.installer.lib.impl/src/main/java/org/gvsig/installer/lib/impl/DefaultInstallerManager.java | ||
---|---|---|
28 | 28 |
package org.gvsig.installer.lib.impl; |
29 | 29 |
|
30 | 30 |
import java.io.File; |
31 |
import java.io.IOException; |
|
32 |
import java.io.InputStream; |
|
31 | 33 |
import java.net.URL; |
32 | 34 |
import java.text.MessageFormat; |
33 | 35 |
import java.util.ArrayList; |
36 |
import java.util.HashSet; |
|
34 | 37 |
import java.util.List; |
38 |
import java.util.Set; |
|
35 | 39 |
|
36 | 40 |
import org.gvsig.installer.lib.api.DependenciesCalculator; |
37 | 41 |
import org.gvsig.installer.lib.api.Dependency; |
... | ... | |
74 | 78 |
|
75 | 79 |
private URL BaseDownloadURL = null; |
76 | 80 |
private String version = null; |
77 |
private List<File> repositoriesPathsList = null;
|
|
78 |
private File defaultAddonRepository = null;
|
|
81 |
private Set<File> repositoriesPaths = null;
|
|
82 |
private File defaultRepositoriesPath = null;
|
|
79 | 83 |
|
80 | 84 |
public DefaultInstallerManager() { |
81 | 85 |
super(new DefaultInstallerProviderManager()); |
82 |
repositoriesPathsList = new ArrayList<File>();
|
|
86 |
repositoriesPaths = new HashSet<File>();
|
|
83 | 87 |
} |
84 | 88 |
|
85 | 89 |
public String getPackageSetNameFormat() { |
... | ... | |
106 | 110 |
this.packageIndexNameFormat = packageIndexNameFormat; |
107 | 111 |
} |
108 | 112 |
|
109 |
// public MakePluginPackageService getMakePluginPackageService( |
|
110 |
// File pluginsDirectory) throws MakePluginPackageServiceException { |
|
111 |
// ExtensionPoint ep = extensionPoints |
|
112 |
// .add(INSTALLER_MANAGER_EXTENSION_POINT); |
|
113 |
// try { |
|
114 |
// Object[] args = new Object[] { this, pluginsDirectory }; |
|
115 |
// return (MakePluginPackageService) ep.create( |
|
116 |
// INSTALLER_CREATION_SERVICE_NAME, args); |
|
117 |
// } catch (Exception e) { |
|
118 |
// throw new MakePluginPackageServiceException( |
|
119 |
// "Exception creating the installer service to create installers", |
|
120 |
// e); |
|
121 |
// } |
|
122 |
// } |
|
123 |
|
|
124 | 113 |
public MakePluginPackageService getMakePluginPackageService() |
125 | 114 |
throws MakePluginPackageServiceException { |
126 | 115 |
ExtensionPoint ep = extensionPoints |
... | ... | |
311 | 300 |
this.version = version; |
312 | 301 |
} |
313 | 302 |
|
303 |
public File getDefaultLocalAddonRepository() { |
|
304 |
return this.defaultRepositoriesPath; |
|
305 |
} |
|
306 |
|
|
307 |
public void setDefaultLocalAddonRepository(File defaultAddonsRepository) { |
|
308 |
this.defaultRepositoriesPath = defaultAddonsRepository; |
|
309 |
this.repositoriesPaths.add(defaultAddonsRepository); |
|
310 |
} |
|
311 |
|
|
314 | 312 |
public void addLocalAddonRepository(File path) { |
315 |
if (path.isDirectory() && path.exists()) { |
|
316 |
repositoriesPathsList.add(path); |
|
317 |
} |
|
313 |
repositoriesPaths.add(path); |
|
318 | 314 |
} |
319 | 315 |
|
320 | 316 |
public List<File> getLocalAddonRepositories() { |
321 |
return repositoriesPathsList; |
|
317 |
List<File> l = new ArrayList<File>(); |
|
318 |
l.addAll(repositoriesPaths); |
|
319 |
return l; |
|
322 | 320 |
} |
323 | 321 |
|
324 | 322 |
public List<File> getAddonFolders() { |
325 |
List<File> addonFoldersList = new ArrayList<File>();
|
|
323 |
List<File> addonFolders = new ArrayList<File>(); |
|
326 | 324 |
|
327 | 325 |
// Para cada directorio en repositoriesPathsList |
328 |
for (int i = 0; i < repositoriesPathsList.size(); i++) { |
|
329 |
File repoPath = repositoriesPathsList.get(i); |
|
326 |
List<File> localAddonRepositories = this.getLocalAddonRepositories(); |
|
327 |
for (int i = 0; i < localAddonRepositories.size(); i++) { |
|
328 |
File repoPath = localAddonRepositories.get(i); |
|
330 | 329 |
if (repoPath.isDirectory() && repoPath.exists()) { |
331 | 330 |
File[] folderRepoList = repoPath.listFiles(); |
332 | 331 |
|
... | ... | |
334 | 333 |
for (int j = 0; j < folderRepoList.length; j++) { |
335 | 334 |
File addonFolder = folderRepoList[j]; |
336 | 335 |
if (addonFolder.isDirectory()) { |
337 |
File[] fileList = addonFolder.listFiles(); |
|
338 |
|
|
339 |
for (int k = 0; k < fileList.length; k++) { |
|
340 |
File file = fileList[k]; |
|
341 |
// si tiene un package.info dentro |
|
342 |
if (file.getName().equals("package.info")) { |
|
343 |
addonFoldersList.add(addonFolder); |
|
344 |
break; |
|
345 |
} |
|
336 |
File pkginfofile = new File(addonFolder, "package.info"); |
|
337 |
if (pkginfofile.exists()) { |
|
338 |
addonFolders.add(addonFolder); |
|
339 |
break; |
|
346 | 340 |
} |
347 | 341 |
} |
348 | 342 |
|
... | ... | |
350 | 344 |
} |
351 | 345 |
} |
352 | 346 |
|
353 |
return addonFoldersList;
|
|
347 |
return addonFolders; |
|
354 | 348 |
} |
355 | 349 |
|
356 | 350 |
public File getAddonFolder(String code) { |
... | ... | |
363 | 357 |
return null; |
364 | 358 |
} |
365 | 359 |
|
366 |
public File getDefaultLocalAddonRepository() { |
|
367 |
return defaultAddonRepository; |
|
360 |
public List<byte[]> getPublicKeys() { |
|
361 |
byte[] rawkey; |
|
362 |
try { |
|
363 |
InputStream is = this.getClass().getResourceAsStream("/org/gvsig/installer/lib/keys/key.public"); |
|
364 |
rawkey = new byte[is.available()]; |
|
365 |
is.read(rawkey); |
|
366 |
is.close(); |
|
367 |
} catch (IOException e) { |
|
368 |
return null; |
|
369 |
} |
|
370 |
List<byte[]> keys = new ArrayList<byte[]>(); |
|
371 |
keys.add(rawkey); |
|
372 |
return keys; |
|
368 | 373 |
} |
369 | 374 |
|
370 |
public void setDefaultLocalAddonRepository(File defaultAddonsRepository) { |
|
371 |
this.defaultAddonRepository = defaultAddonsRepository; |
|
372 |
} |
|
373 |
|
|
374 |
public List getPublicKeys() { |
|
375 |
// TODO Auto-generated method stub |
|
376 |
return null; |
|
377 |
} |
|
378 |
|
|
379 | 375 |
} |
branches/v2_0_0_prep/extensions/org.gvsig.installer/org.gvsig.installer.lib/org.gvsig.installer.lib.impl/src/main/java/org/gvsig/installer/lib/impl/utils/SignUtil.java | ||
---|---|---|
1 |
package org.gvsig.installer.lib.impl.utils; |
|
2 |
|
|
3 |
import java.io.BufferedReader; |
|
4 |
import java.io.File; |
|
5 |
import java.io.FileInputStream; |
|
6 |
import java.io.FileNotFoundException; |
|
7 |
import java.io.FileOutputStream; |
|
8 |
import java.io.FileWriter; |
|
9 |
import java.io.InputStream; |
|
10 |
import java.io.StringReader; |
|
11 |
import java.io.StringWriter; |
|
12 |
import java.security.KeyFactory; |
|
13 |
import java.security.KeyPair; |
|
14 |
import java.security.KeyPairGenerator; |
|
15 |
import java.security.NoSuchAlgorithmException; |
|
16 |
import java.security.NoSuchProviderException; |
|
17 |
import java.security.PrivateKey; |
|
18 |
import java.security.PublicKey; |
|
19 |
import java.security.SecureRandom; |
|
20 |
import java.security.Signature; |
|
21 |
import java.security.spec.EncodedKeySpec; |
|
22 |
import java.security.spec.InvalidKeySpecException; |
|
23 |
import java.security.spec.PKCS8EncodedKeySpec; |
|
24 |
import java.security.spec.X509EncodedKeySpec; |
|
25 |
|
|
26 |
import org.apache.commons.codec.binary.Base64; |
|
27 |
|
|
28 |
public class SignUtil { |
|
29 |
|
|
30 |
public static final int SIGN_OK = 0; |
|
31 |
public static final int SIGN_FAIL = 1; |
|
32 |
public static final int NOT_SIGNED = 2; |
|
33 |
|
|
34 |
private PublicKey pubKey = null; |
|
35 |
private PrivateKey privKey = null; |
|
36 |
|
|
37 |
public static void main(String[] args) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeySpecException, FileNotFoundException { |
|
38 |
new SignUtil().doMain(args); |
|
39 |
} |
|
40 |
|
|
41 |
private void doMain(String[] args) { |
|
42 |
|
|
43 |
try { |
|
44 |
if( "sign".equalsIgnoreCase(getCommand(args)) ) { |
|
45 |
if( !this.canSign() ) { |
|
46 |
System.out.println("Can't locate private key to sign."); |
|
47 |
return; |
|
48 |
} |
|
49 |
this.sign( this.getArg1AsFile(args)); |
|
50 |
System.out.println("File "+this.getArg1(args)+" signed."); |
|
51 |
return; |
|
52 |
} |
|
53 |
|
|
54 |
if( "verify".equalsIgnoreCase(getCommand(args)) ) { |
|
55 |
if( !this.canVerify() ) { |
|
56 |
System.out.println("Can't locate public key to verify."); |
|
57 |
return; |
|
58 |
} |
|
59 |
switch(this.verify(this.getArg1AsFile(args))) { |
|
60 |
case NOT_SIGNED: |
|
61 |
System.out.println("NOT SIGNED"); |
|
62 |
break; |
|
63 |
case SIGN_FAIL: |
|
64 |
System.out.println("SIGN FAIL"); |
|
65 |
break; |
|
66 |
case SIGN_OK: |
|
67 |
System.out.println("SIGN OK"); |
|
68 |
break; |
|
69 |
default: |
|
70 |
System.out.println("ERROR"); |
|
71 |
} |
|
72 |
return; |
|
73 |
} |
|
74 |
|
|
75 |
if( "generateKeys".equalsIgnoreCase(getCommand(args)) ) { |
|
76 |
this.generateKeys(); |
|
77 |
System.out.println("Generate keys ok"); |
|
78 |
return; |
|
79 |
} |
|
80 |
|
|
81 |
System.out.println("Usage: SignUtil sign|verify|generateKeys\n" + |
|
82 |
" sign file\n" + |
|
83 |
" verify file\n" + |
|
84 |
" generateKeys\n"); |
|
85 |
return; |
|
86 |
} catch (Exception e) { |
|
87 |
e.printStackTrace(); |
|
88 |
} |
|
89 |
} |
|
90 |
|
|
91 |
private String getCommand(String[] args) { |
|
92 |
if( args.length>=1) { |
|
93 |
return args[0]; |
|
94 |
} |
|
95 |
return null; |
|
96 |
} |
|
97 |
|
|
98 |
private File getArg1AsFile(String[] args) { |
|
99 |
if( args.length>=2) { |
|
100 |
return new File(args[1]); |
|
101 |
} |
|
102 |
return null; |
|
103 |
} |
|
104 |
|
|
105 |
private String getArg1(String[] args) { |
|
106 |
if( args.length>=2) { |
|
107 |
return args[1]; |
|
108 |
} |
|
109 |
return null; |
|
110 |
} |
|
111 |
|
|
112 |
public SignUtil() { |
|
113 |
loadPrivateKey(); |
|
114 |
loadPublicKey(); |
|
115 |
} |
|
116 |
|
|
117 |
public SignUtil(byte[] publicKey){ |
|
118 |
loadPrivateKey(); |
|
119 |
loadPublicKey(publicKey); |
|
120 |
} |
|
121 |
|
|
122 |
private void loadPrivateKey() { |
|
123 |
File home = new File(System.getProperty("user.home")); |
|
124 |
File keyfile = new File(home, ".gvsig-keys" + File.separatorChar |
|
125 |
+ "key.private"); |
|
126 |
if (keyfile.exists()) { |
|
127 |
try { |
|
128 |
loadPrivateKey(keyfile); |
|
129 |
} catch (Exception e) { |
|
130 |
// Ignore errors |
|
131 |
} |
|
132 |
} |
|
133 |
} |
|
134 |
|
|
135 |
private PrivateKey loadPrivateKey(File key) { |
|
136 |
try { |
|
137 |
byte[] rawkey; |
|
138 |
rawkey = loadFileAsByteArray(new FileInputStream(key)); |
|
139 |
EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(rawkey); |
|
140 |
KeyFactory keyFactory = KeyFactory.getInstance("DSA", "SUN"); |
|
141 |
this.privKey = keyFactory.generatePrivate(keySpec); |
|
142 |
} catch (Exception e) { |
|
143 |
this.privKey = null; |
|
144 |
} |
|
145 |
return this.privKey; |
|
146 |
} |
|
147 |
|
|
148 |
private PublicKey loadPublicKey() { |
|
149 |
File home = new File(System.getProperty("user.home")); |
|
150 |
File keyfile = new File(home, ".gvsig-keys" + File.separatorChar |
|
151 |
+ "key.public"); |
|
152 |
if (keyfile.exists()) { |
|
153 |
return loadPublicKey(loadFileAsByteArray(keyfile)); |
|
154 |
} |
|
155 |
return null; |
|
156 |
} |
|
157 |
private PublicKey loadPublicKey(byte[] rawkey) { |
|
158 |
try { |
|
159 |
EncodedKeySpec keySpec = new X509EncodedKeySpec(rawkey); |
|
160 |
KeyFactory keyFactory; |
|
161 |
keyFactory = KeyFactory.getInstance("DSA", "SUN"); |
|
162 |
this.pubKey = keyFactory.generatePublic(keySpec); |
|
163 |
} catch (Exception e) { |
|
164 |
this.pubKey = null; |
|
165 |
} |
|
166 |
return this.pubKey; |
|
167 |
} |
|
168 |
|
|
169 |
private PublicKey getPublicKey() { |
|
170 |
return this.pubKey; |
|
171 |
} |
|
172 |
|
|
173 |
private PrivateKey getPrivateKey() { |
|
174 |
return this.privKey; |
|
175 |
} |
|
176 |
|
|
177 |
private byte[] loadFileAsByteArray(InputStream in) { |
|
178 |
byte[] alldata; |
|
179 |
try { |
|
180 |
alldata = new byte[in.available()]; |
|
181 |
in.read(alldata); |
|
182 |
in.close(); |
|
183 |
} catch (Exception e) { |
|
184 |
e.printStackTrace(); |
|
185 |
return null; |
|
186 |
} |
|
187 |
return alldata; |
|
188 |
} |
|
189 |
|
|
190 |
private byte[] loadFileAsByteArray(File file) { |
|
191 |
try { |
|
192 |
return loadFileAsByteArray(new FileInputStream(file)); |
|
193 |
} catch (FileNotFoundException e) { |
|
194 |
e.printStackTrace(); |
|
195 |
return null; |
|
196 |
} |
|
197 |
} |
|
198 |
|
|
199 |
private String getData(byte[] alldata) { |
|
200 |
BufferedReader reader = new BufferedReader(new StringReader( |
|
201 |
new String(alldata))); |
|
202 |
StringWriter writer = new StringWriter(); |
|
203 |
String line; |
|
204 |
try { |
|
205 |
boolean inSignature = false; |
|
206 |
while ((line = reader.readLine()) != null) { |
|
207 |
if (inSignature) { |
|
208 |
if (line.startsWith("## END SIGNATURE")) { |
|
209 |
inSignature = false; |
|
210 |
} |
|
211 |
} else { |
|
212 |
if (line.startsWith("## BEGIN SIGNATURE")) { |
|
213 |
inSignature = true; |
|
214 |
} else { |
|
215 |
writer.append(line); |
|
216 |
writer.append("\n"); |
|
217 |
} |
|
218 |
} |
|
219 |
} |
|
220 |
writer.close(); |
|
221 |
} catch (Exception e) { |
|
222 |
e.printStackTrace(); |
|
223 |
return null; |
|
224 |
} |
|
225 |
return writer.toString(); |
|
226 |
} |
|
227 |
|
|
228 |
private byte[] getSignature(byte[] alldata) { |
|
229 |
BufferedReader reader = new BufferedReader(new StringReader( |
|
230 |
new String(alldata))); |
|
231 |
StringWriter writer = new StringWriter(); |
|
232 |
String line; |
|
233 |
try { |
|
234 |
boolean inSignature = false; |
|
235 |
while ((line = reader.readLine()) != null) { |
|
236 |
if (inSignature) { |
|
237 |
if (line.startsWith("## END SIGNATURE")) { |
|
238 |
inSignature = false; |
|
239 |
} else { |
|
240 |
writer.append(line); |
|
241 |
writer.append("\n"); |
|
242 |
} |
|
243 |
} else { |
|
244 |
if (line.startsWith("## BEGIN SIGNATURE")) { |
|
245 |
inSignature = true; |
|
246 |
} |
|
247 |
} |
|
248 |
} |
|
249 |
writer.close(); |
|
250 |
} catch (Exception e) { |
|
251 |
e.printStackTrace(); |
|
252 |
return null; |
|
253 |
} |
|
254 |
String s = writer.toString(); |
|
255 |
if (s.length() < 1) { |
|
256 |
return null; |
|
257 |
} |
|
258 |
Base64 coder = new Base64(60); |
|
259 |
return coder.decode(s); |
|
260 |
} |
|
261 |
|
|
262 |
public void sign(File file) { |
|
263 |
Signature dsa; |
|
264 |
Base64 coder = new Base64(60); |
|
265 |
|
|
266 |
try { |
|
267 |
String data = getData(loadFileAsByteArray(file)); |
|
268 |
dsa = Signature.getInstance("SHA1withDSA", "SUN"); |
|
269 |
dsa.initSign(getPrivateKey()); |
|
270 |
dsa.update(data.getBytes()); |
|
271 |
|
|
272 |
String sig = coder.encodeAsString(dsa.sign()); |
|
273 |
String[] lines = sig.split("\n"); |
|
274 |
|
|
275 |
FileWriter fw = new FileWriter(file); |
|
276 |
fw.append(data); |
|
277 |
fw.append("## BEGIN SIGNATURE\n"); |
|
278 |
for (int i = 0; i < lines.length; i++) { |
|
279 |
fw.append("## "); |
|
280 |
fw.append(lines[i]); |
|
281 |
fw.append("\n"); |
|
282 |
} |
|
283 |
fw.append("## END SIGNATURE\n"); |
|
284 |
fw.close(); |
|
285 |
|
|
286 |
} catch (Exception e) { |
|
287 |
e.printStackTrace(); |
|
288 |
} |
|
289 |
|
|
290 |
} |
|
291 |
|
|
292 |
public int verify(File file) { |
|
293 |
return verify(loadFileAsByteArray(file)); |
|
294 |
} |
|
295 |
|
|
296 |
public int verify(byte[] alldata) { |
|
297 |
try { |
|
298 |
String data = getData(alldata); |
|
299 |
byte[] signature = getSignature(alldata); |
|
300 |
if (signature == null) { |
|
301 |
return NOT_SIGNED; |
|
302 |
} |
|
303 |
Signature dsa; |
|
304 |
dsa = Signature.getInstance("SHA1withDSA", "SUN"); |
|
305 |
dsa.initVerify(getPublicKey()); |
|
306 |
dsa.update(data.getBytes()); |
|
307 |
if (!dsa.verify(signature)) { |
|
308 |
return SIGN_FAIL; |
|
309 |
} |
|
310 |
return SIGN_OK; |
|
311 |
|
|
312 |
} catch (Exception e) { |
|
313 |
e.printStackTrace(); |
|
314 |
} |
|
315 |
return NOT_SIGNED; |
|
316 |
} |
|
317 |
|
|
318 |
public void generateKeys() { |
|
319 |
try { |
|
320 |
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA", |
|
321 |
"SUN"); |
|
322 |
SecureRandom random = SecureRandom.getInstance("SHA1PRNG", |
|
323 |
"SUN"); |
|
324 |
keyGen.initialize(1024, random); |
|
325 |
|
|
326 |
KeyPair pair = keyGen.generateKeyPair(); |
|
327 |
PrivateKey privKey = pair.getPrivate(); |
|
328 |
PublicKey pubKey = pair.getPublic(); |
|
329 |
|
|
330 |
FileOutputStream fos; |
|
331 |
fos = new FileOutputStream("key.private"); |
|
332 |
fos.write(privKey.getEncoded()); |
|
333 |
fos.close(); |
|
334 |
|
|
335 |
fos = new FileOutputStream("key.public"); |
|
336 |
fos.write(pubKey.getEncoded()); |
|
337 |
fos.close(); |
|
338 |
|
|
339 |
System.out |
|
340 |
.println("Generados los ficheros key.private y key.public en la carpeta corriente."); |
|
341 |
System.out |
|
342 |
.println("Por defecto la aplicaccion las buscara en la carpeta $HOME/.gvsig-keys ."); |
|
343 |
} catch (Exception e) { |
|
344 |
e.printStackTrace(); |
|
345 |
} |
|
346 |
|
|
347 |
} |
|
348 |
|
|
349 |
public boolean canSign() { |
|
350 |
if( this.getPrivateKey() == null ) { |
|
351 |
return false; |
|
352 |
} |
|
353 |
return true; |
|
354 |
} |
|
355 |
|
|
356 |
public boolean canVerify() { |
|
357 |
if( this.getPublicKey() == null ) { |
|
358 |
return false; |
|
359 |
} |
|
360 |
return true; |
|
361 |
} |
|
362 |
|
|
363 |
|
|
364 |
} |
|
0 | 365 |
branches/v2_0_0_prep/extensions/org.gvsig.installer/org.gvsig.installer.lib/org.gvsig.installer.lib.impl/pom.xml | ||
---|---|---|
1 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
|
1 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|
2 |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
|
2 | 3 |
<modelVersion>4.0.0</modelVersion> |
3 | 4 |
<artifactId>org.gvsig.installer.lib.impl</artifactId> |
4 | 5 |
<packaging>jar</packaging> |
... | ... | |
7 | 8 |
<groupId>org.gvsig</groupId> |
8 | 9 |
<artifactId>org.gvsig.installer.lib</artifactId> |
9 | 10 |
<version>1.0.1-SNAPSHOT</version> |
10 |
</parent>
|
|
11 |
</parent> |
|
11 | 12 |
<dependencies> |
12 | 13 |
<dependency> |
13 | 14 |
<groupId>org.gvsig</groupId> |
14 | 15 |
<artifactId>org.gvsig.installer.lib.api</artifactId> |
15 | 16 |
<version>1.0.1-SNAPSHOT</version> |
16 |
<scope>compile</scope>
|
|
17 |
<scope>compile</scope>
|
|
17 | 18 |
</dependency> |
18 | 19 |
<dependency> |
19 | 20 |
<groupId>org.gvsig</groupId> |
20 | 21 |
<artifactId>org.gvsig.installer.lib.spi</artifactId> |
21 | 22 |
<version>1.0.1-SNAPSHOT</version> |
22 |
<scope>compile</scope>
|
|
23 |
<scope>compile</scope>
|
|
23 | 24 |
</dependency> |
24 |
<dependency>
|
|
25 |
<groupId>org.gvsig</groupId>
|
|
26 |
<artifactId>org.gvsig.tools.lib</artifactId>
|
|
27 |
<scope>compile</scope>
|
|
28 |
</dependency>
|
|
29 |
<dependency>
|
|
30 |
<groupId>org.slf4j</groupId>
|
|
31 |
<artifactId>slf4j-api</artifactId>
|
|
32 |
<scope>compile</scope>
|
|
33 |
</dependency>
|
|
25 |
<dependency>
|
|
26 |
<groupId>org.gvsig</groupId>
|
|
27 |
<artifactId>org.gvsig.tools.lib</artifactId>
|
|
28 |
<scope>compile</scope>
|
|
29 |
</dependency>
|
|
30 |
<dependency>
|
|
31 |
<groupId>org.slf4j</groupId>
|
|
32 |
<artifactId>slf4j-api</artifactId>
|
|
33 |
<scope>compile</scope>
|
|
34 |
</dependency>
|
|
34 | 35 |
<!-- TEST --> |
35 | 36 |
<dependency> |
36 | 37 |
<groupId>org.gvsig</groupId> |
... | ... | |
43 | 44 |
<version>1.0.1-SNAPSHOT</version> |
44 | 45 |
<scope>test</scope> |
45 | 46 |
</dependency> |
47 |
<dependency> |
|
48 |
<groupId>commons-codec</groupId> |
|
49 |
<artifactId>commons-codec</artifactId> |
|
50 |
<version>1.6</version> |
|
51 |
</dependency> |
|
46 | 52 |
</dependencies> |
47 | 53 |
</project> |
branches/v2_0_0_prep/extensions/org.gvsig.installer/org.gvsig.installer.lib/org.gvsig.installer.lib.api/src/main/java/org/gvsig/installer/lib/api/InstallerManager.java | ||
---|---|---|
420 | 420 |
*/ |
421 | 421 |
public File getDefaultLocalAddonRepository(); |
422 | 422 |
|
423 |
public List getPublicKeys(); |
|
423 |
public List<byte[]> getPublicKeys();
|
|
424 | 424 |
|
425 | 425 |
|
426 | 426 |
} |
branches/v2_0_0_prep/extensions/org.gvsig.installer/org.gvsig.installer.maven/src/main/java/org/gvsig/installer/maven/GeneratePackageInfoMojo.java | ||
---|---|---|
256 | 256 |
new DefaultLibrariesInitializer().fullInitialize(); |
257 | 257 |
|
258 | 258 |
InstallerManager manager = InstallerLocator.getInstallerManager(); |
259 |
|
|
260 |
manager.setDefaultLocalAddonRepository(pluginsFolder); |
|
261 |
MakePluginPackageService makePluginService = manager.getMakePluginPackageService(); |
|
259 | 262 |
|
260 |
MakePluginPackageService makePluginService = manager |
|
261 |
.getMakePluginPackageService(); |
|
262 |
|
|
263 | 263 |
// Get and fill the package info data |
264 |
PackageInfo info = makePluginService |
|
265 |
.getPluginPackageInfo(artifactId); |
|
264 |
PackageInfo info = makePluginService.getPluginPackageInfo(artifactId); |
|
266 | 265 |
|
267 | 266 |
// info.setCode(artifactId); |
268 | 267 |
info.setDescription(description); |
branches/v2_0_0_prep/extensions/org.gvsig.installer/org.gvsig.installer.swing/org.gvsig.installer.swing.impl/src/main/java/org/gvsig/installer/swing/impl/execution/panel/model/PackagesTableModel.java | ||
---|---|---|
58 | 58 |
OFFICIAL_NOT_RECOMMENDED, OFFICIAL_RECOMMENDED, NOT_OFFICIAL_RECOMMENDED, NOT_OFFICIAL_NOT_RECOMMENDED |
59 | 59 |
} |
60 | 60 |
|
61 |
public enum PackageOsAndArchitecture { |
|
62 |
WINDOLS_32, WINDOLS_64, LINUX_32, LINUX_64, ALL, OTHER |
|
61 |
public class PackageOsAndArchitecture { |
|
62 |
public String os; |
|
63 |
public String arch; |
|
63 | 64 |
} |
65 |
|
|
66 |
// |
|
67 |
// public enum PackageOsAndArchitecture { |
|
68 |
// WINDOLS_32, WINDOLS_64, LINUX_32, LINUX_64, ALL, OTHER |
|
69 |
// } |
|
64 | 70 |
|
65 | 71 |
private TablePackageInfo[] installerInfos = null; |
66 | 72 |
|
... | ... | |
319 | 325 |
* @return |
320 | 326 |
*/ |
321 | 327 |
private PackageOsAndArchitecture checkPackageSystem(int rowIndex) { |
328 |
PackageOsAndArchitecture oSArch = new PackageOsAndArchitecture(); |
|
322 | 329 |
TablePackageInfo tableInfo = installerInfos[rowIndex]; |
323 | 330 |
PackageInfo installerInfo = tableInfo.getPackageInfo(); |
324 |
PackageOsAndArchitecture oSArch; |
|
325 |
|
|
326 |
if (installerInfo.getOperatingSystem().equals( |
|
327 |
installerInfo.getArchitecture())) { |
|
328 |
oSArch = PackageOsAndArchitecture.ALL; |
|
329 |
} else if ((installerInfo.getOperatingSystem().equals("lin"))) { |
|
330 |
if (installerInfo.getArchitecture().equals("x86")) { |
|
331 |
oSArch = PackageOsAndArchitecture.LINUX_32; |
|
332 |
} else { |
|
333 |
oSArch = PackageOsAndArchitecture.LINUX_64; |
|
334 |
} |
|
335 |
} else if ((installerInfo.getOperatingSystem().equals("win"))) { |
|
336 |
if (installerInfo.getArchitecture().equals("x86")) { |
|
337 |
oSArch = PackageOsAndArchitecture.WINDOLS_32; |
|
338 |
} else { |
|
339 |
oSArch = PackageOsAndArchitecture.WINDOLS_64; |
|
340 |
} |
|
341 |
} else { |
|
342 |
oSArch = PackageOsAndArchitecture.OTHER; |
|
343 |
} |
|
331 |
oSArch.os = installerInfo.getOperatingSystem(); |
|
332 |
oSArch.arch = installerInfo.getArchitecture(); |
|
344 | 333 |
return oSArch; |
345 | 334 |
} |
346 | 335 |
|
branches/v2_0_0_prep/extensions/org.gvsig.installer/org.gvsig.installer.swing/org.gvsig.installer.swing.impl/src/main/java/org/gvsig/installer/swing/impl/execution/panel/renderers/OsAndArchitectureCellRenderer.java | ||
---|---|---|
30 | 30 |
import javax.swing.JTable; |
31 | 31 |
import javax.swing.table.DefaultTableCellRenderer; |
32 | 32 |
|
33 |
import org.gvsig.installer.lib.api.InstallerManager; |
|
33 | 34 |
import org.gvsig.installer.swing.impl.execution.panel.model.PackagesTableModel.PackageOsAndArchitecture; |
34 | 35 |
|
35 | 36 |
/** |
... | ... | |
48 | 49 |
public Component getTableCellRendererComponent(JTable table, Object value, |
49 | 50 |
boolean isSelected, boolean hasFocus, int row, int column) { |
50 | 51 |
|
52 |
String tooltip; |
|
51 | 53 |
Icon icon; |
54 |
URL resource; |
|
55 |
JLabel check = new JLabel(); |
|
52 | 56 |
PackageOsAndArchitecture osArch = (PackageOsAndArchitecture) value; |
53 |
JLabel check = new JLabel(); |
|
54 |
URL resource; |
|
55 | 57 |
|
56 |
switch (osArch) { |
|
57 |
|
|
58 |
case LINUX_32: |
|
59 |
resource = this.getClass().getResource("/images/linux_x86.png"); |
|
60 |
icon = new ImageIcon(resource); |
|
61 |
check.setIcon(icon); |
|
62 |
check.setToolTipText("Linux x86"); |
|
58 |
if( InstallerManager.OS.ALL.equalsIgnoreCase(osArch.os) ) { |
|
63 | 59 |
return check; |
64 |
|
|
65 |
case LINUX_64: |
|
66 |
resource = this.getClass().getResource("/images/linux_AMD64.png"); |
|
67 |
icon = new ImageIcon(resource); |
|
68 |
check.setIcon(icon); |
|
69 |
check.setToolTipText("Linux AMD64"); |
|
70 |
return check; |
|
71 |
|
|
72 |
case WINDOLS_32: |
|
73 |
resource = this.getClass().getResource("/images/windows_x86.png"); |
|
74 |
icon = new ImageIcon(resource); |
|
75 |
check.setIcon(icon); |
|
76 |
check.setToolTipText("Windows x86"); |
|
77 |
return check; |
|
78 |
|
|
79 |
case WINDOLS_64: |
|
80 |
resource = this.getClass().getResource("/images/windows_AMD64.png"); |
|
81 |
icon = new ImageIcon(resource); |
|
82 |
check.setIcon(icon); |
|
83 |
check.setToolTipText("Windows AMD64"); |
|
84 |
return check; |
|
85 |
|
|
86 |
default: |
|
87 |
return check; |
|
60 |
|
|
61 |
} else if( InstallerManager.OS.LINUX.equalsIgnoreCase(osArch.os) ) { |
|
62 |
if( InstallerManager.ARCH.X86.equalsIgnoreCase(osArch.arch) ) { |
|
63 |
tooltip = "Linux 32 bits"; |
|
64 |
} else if( InstallerManager.ARCH.X86_64.equalsIgnoreCase(osArch.arch) ) { |
|
65 |
tooltip = "Linux 64 bits"; |
|
66 |
} else { |
|
67 |
tooltip = "Linux " + osArch; |
|
68 |
} |
|
69 |
} else if( InstallerManager.OS.WINDOWS.equalsIgnoreCase(osArch.os) ) { |
|
70 |
if( InstallerManager.ARCH.X86.equalsIgnoreCase(osArch.arch) ) { |
|
71 |
tooltip = "Windows 32 bits"; |
|
72 |
} else if( InstallerManager.ARCH.X86_64.equalsIgnoreCase(osArch.arch) ) { |
|
73 |
tooltip = "Windows 64 bits"; |
|
74 |
} else { |
|
75 |
tooltip = "Windows " + osArch; |
|
76 |
} |
|
77 |
} else { |
|
78 |
if( InstallerManager.ARCH.X86.equalsIgnoreCase(osArch.arch) ) { |
|
79 |
tooltip = osArch.os + " 32 bits"; |
|
80 |
} else if( InstallerManager.ARCH.X86_64.equalsIgnoreCase(osArch.arch) ) { |
|
81 |
tooltip = osArch.os + " 64 bits"; |
|
82 |
} else { |
|
83 |
tooltip = osArch.os + " " + osArch.arch; |
|
84 |
} |
|
88 | 85 |
} |
89 |
|
|
86 |
try { |
|
87 |
resource = this.getClass().getResource("/images/platform_14x14_"+osArch.os+"_"+osArch.arch+".png"); |
|
88 |
} catch( Exception ex) { |
|
89 |
resource = null; |
|
90 |
} |
|
91 |
if( resource == null ) { |
|
92 |
resource = this.getClass().getResource("/images/platform_14x14_unknow_unknow.png"); |
|
93 |
} |
|
94 |
icon = new ImageIcon(resource); |
|
95 |
check.setIcon(icon); |
|
96 |
check.setToolTipText(tooltip); |
|
97 |
return check; |
|
90 | 98 |
} |
91 | 99 |
|
92 | 100 |
} |
Also available in: Unified diff