tp2 finit
This commit is contained in:
parent
141fd0f1ef
commit
a655ebe44d
16
TD/TD2/a.php
16
TD/TD2/a.php
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
require('./config.php');
|
require('./config.php'); //Contient le chemin vers le fichier de config d'openssl
|
||||||
|
|
||||||
$dn = array(
|
$dn = array(
|
||||||
"countryName" => "FR",
|
"countryName" => "FR",
|
||||||
@ -12,12 +12,14 @@ $dn = array(
|
|||||||
"emailAddress" => "iut@univ.fr"
|
"emailAddress" => "iut@univ.fr"
|
||||||
);
|
);
|
||||||
|
|
||||||
$pk = openssl_pkey_new($config);
|
//on créé un tableau de données pour la création du certificat
|
||||||
$req = openssl_csr_new($dn, $pk, $config);
|
|
||||||
$certif = openssl_csr_sign($req, null, $pk, (365*3), $config);
|
$pk = openssl_pkey_new($config); //création de clé privée
|
||||||
$exportCertif = openssl_x509_export_to_file($certif, "./a/certificat");
|
$req = openssl_csr_new($dn, $pk, $config); // création d'un CSR
|
||||||
$exportReq = openssl_csr_export_to_file($req, "./a/requete");
|
$certif = openssl_csr_sign($req, null, $pk, (365*3), $config); //création d'un certificat valide pour 3 ans
|
||||||
$exportKey = openssl_pkey_export_to_file($pk, "./a/clePrivee", null, $config);
|
$exportCertif = openssl_x509_export_to_file($certif, "./a/certificat"); //exportation certificat
|
||||||
|
$exportReq = openssl_csr_export_to_file($req, "./a/requete"); //exportation CSR
|
||||||
|
$exportKey = openssl_pkey_export_to_file($pk, "./a/clePrivee", null, $config); //exportation cléPrivée
|
||||||
|
|
||||||
echo "Certificat exporté<br />";
|
echo "Certificat exporté<br />";
|
||||||
echo "Requête exportée<br />";
|
echo "Requête exportée<br />";
|
||||||
|
18
TD/TD2/b.php
18
TD/TD2/b.php
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
require('./config.php');
|
require('./config.php'); //Contient le chemin vers le fichier de config d'openssl
|
||||||
|
|
||||||
if( isset($_POST["Pays"]) && $_POST["Pays"] != '' &&
|
if( isset($_POST["Pays"]) && $_POST["Pays"] != '' &&
|
||||||
isset($_POST["Département"]) && $_POST["Département"] != '' &&
|
isset($_POST["Département"]) && $_POST["Département"] != '' &&
|
||||||
@ -9,7 +9,7 @@ if( isset($_POST["Pays"]) && $_POST["Pays"] != '' &&
|
|||||||
isset($_POST["Unite"]) && $_POST["Unite"] != '' &&
|
isset($_POST["Unite"]) && $_POST["Unite"] != '' &&
|
||||||
isset($_POST["Nom"]) && $_POST["Nom"] != '' &&
|
isset($_POST["Nom"]) && $_POST["Nom"] != '' &&
|
||||||
isset($_POST["Prenom"]) && $_POST["Prenom"] != '' &&
|
isset($_POST["Prenom"]) && $_POST["Prenom"] != '' &&
|
||||||
isset($_POST["Email"]) && $_POST["Email"] != '' ) {
|
isset($_POST["Email"]) && $_POST["Email"] != '' ) { //vérification que tous les champs du formulaires sont inscrits
|
||||||
$dn = array(
|
$dn = array(
|
||||||
"countryName" => $_POST["Pays"],
|
"countryName" => $_POST["Pays"],
|
||||||
"stateOrProvinceName" => $_POST["Département"],
|
"stateOrProvinceName" => $_POST["Département"],
|
||||||
@ -18,13 +18,13 @@ if( isset($_POST["Pays"]) && $_POST["Pays"] != '' &&
|
|||||||
"organizationalUnitName" => $_POST["Unite"],
|
"organizationalUnitName" => $_POST["Unite"],
|
||||||
"commonName" => '$_POST["Nom"]' . ' ' .'$_POST["Prenom"]',
|
"commonName" => '$_POST["Nom"]' . ' ' .'$_POST["Prenom"]',
|
||||||
"emailAddress" => $_POST["Email"]
|
"emailAddress" => $_POST["Email"]
|
||||||
);
|
); //on créé un tableau de données pour la création du certificat à partir des données du formulatire
|
||||||
$pk = openssl_pkey_new($config);
|
$pk = openssl_pkey_new($config);//création de clé privée
|
||||||
$req = openssl_csr_new($dn, $pk, $config);
|
$req = openssl_csr_new($dn, $pk, $config);// création d'un CSR
|
||||||
$certif = openssl_csr_sign($req, null, $pk, (365), $config);
|
$certif = openssl_csr_sign($req, null, $pk, (365), $config); //création d'un certificat valide pour 1 an
|
||||||
$exportCertif = openssl_x509_export_to_file($certif, "./b/certificat");
|
$exportCertif = openssl_x509_export_to_file($certif, "./b/certificat"); //exportation certificat
|
||||||
$exportReq = openssl_csr_export_to_file($req, "./b/requete");
|
$exportReq = openssl_csr_export_to_file($req, "./b/requete"); //exportation CSR
|
||||||
$exportKey = openssl_pkey_export_to_file($pk, "./b/clePrivee", null, $config);
|
$exportKey = openssl_pkey_export_to_file($pk, "./b/clePrivee", null, $config); //exportation cléPrivée
|
||||||
|
|
||||||
echo "Certificat exporté<br />";
|
echo "Certificat exporté<br />";
|
||||||
echo "Requête exportée<br />";
|
echo "Requête exportée<br />";
|
||||||
|
@ -6,7 +6,9 @@ $ret = "";
|
|||||||
$deret = "";
|
$deret = "";
|
||||||
if(isset($_POST["Code"]) && $_POST["Code"] != '') {
|
if(isset($_POST["Code"]) && $_POST["Code"] != '') {
|
||||||
openssl_public_encrypt($_POST["Code"], $ret, openssl_csr_get_public_key(file_get_contents("./b/requete")));
|
openssl_public_encrypt($_POST["Code"], $ret, openssl_csr_get_public_key(file_get_contents("./b/requete")));
|
||||||
|
//on crypte le texte (données formulaire | variable dans laquelle stocker les données cryptées | clé publique pour crypter)
|
||||||
openssl_private_decrypt($ret,$deret,file_get_contents("./b/clePrivee"));
|
openssl_private_decrypt($ret,$deret,file_get_contents("./b/clePrivee"));
|
||||||
|
//on décrypte les données (données cryptées | variable dans laquelle stocker les données déchiffrées | clé privée à utiliser)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
34
TD/TD2/d.php
34
TD/TD2/d.php
@ -1,15 +1,37 @@
|
|||||||
<?php
|
<?php
|
||||||
|
$dl = false;
|
||||||
require('./config.php');
|
require('./config.php');
|
||||||
|
|
||||||
|
if(isset($_POST['Envoyer'])) {
|
||||||
|
if(!empty($_FILES['File'])) {
|
||||||
|
$fichier = $_FILES['File'];
|
||||||
|
|
||||||
|
$uploadDirectory = "./d/"; // fichier d'upload
|
||||||
|
$fileInfo = new SplFileInfo($_FILES['File']['name']); // préparation du fichier pour upload
|
||||||
|
$nouveauFichier = $fileInfo->getFilename();
|
||||||
|
|
||||||
|
$pathToSave = $uploadDirectory.$nouveauFichier;
|
||||||
|
|
||||||
|
move_uploaded_file($_FILES['File']['tmp_name'], $pathToSave);
|
||||||
|
|
||||||
|
openssl_sign(file_get_contents($pathToSave), $export, file_get_contents("./b/clePrivee"));
|
||||||
|
file_put_contents("./d/signature", $export);
|
||||||
|
$dl = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<html>
|
<html>
|
||||||
<form method="POST" action="c.php">
|
<form method="POST" action="d.php" enctype="multipart/form-data">
|
||||||
<label for="Code">Fichier</label> <input id="File" name="File" value=""/><br />
|
<label for="File">Fichier : </label><input type="file" id="File" name="File" value=""/><br />
|
||||||
<input type="submit" name="Envoyer" value="Envoyer" />
|
<input id="Envoyer" type="submit" name="Envoyer" value="Envoyer" />
|
||||||
</form>
|
</form>
|
||||||
<p>Texte chiffré : <?php echo $ret?></p>
|
|
||||||
<p>Texte déchiffré : <?php echo $deret?></p>
|
<?php
|
||||||
|
if($dl) {
|
||||||
|
echo '<h2>Télécharger signature</h2>'
|
||||||
|
.'<a href ="./d/signature">Télécharger</a>';
|
||||||
|
}
|
||||||
|
?>
|
||||||
</html>
|
</html>
|
BIN
TD/TD2/d/Sans titre.png.png
Normal file
BIN
TD/TD2/d/Sans titre.png.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 163 KiB |
BIN
TD/TD2/d/signature
Normal file
BIN
TD/TD2/d/signature
Normal file
Binary file not shown.
46
TD/TD2/e.php
Normal file
46
TD/TD2/e.php
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
$ok = false;
|
||||||
|
$filesNotUploaded = true;
|
||||||
|
require('./config.php');
|
||||||
|
|
||||||
|
if(isset($_POST['Envoyer'])) {
|
||||||
|
if(!empty($_FILES['File'])) {
|
||||||
|
$fichier = $_FILES['File'];
|
||||||
|
|
||||||
|
$uploadDirectory = "./e/"; // fichier d'upload
|
||||||
|
|
||||||
|
$fileInfoF = new SplFileInfo($_FILES['File']['name']); // préparation du fichier pour upload
|
||||||
|
$fileInfoS = new SplFileInfo($_FILES['Signature']['name']); // préparation du fichier pour upload
|
||||||
|
|
||||||
|
$nouveauFichierF = $fileInfoF->getFilename();
|
||||||
|
$nouveauFichierS = $fileInfoS->getFilename();
|
||||||
|
|
||||||
|
$pathToSaveF = $uploadDirectory.$nouveauFichierF;
|
||||||
|
$pathToSaveS = $uploadDirectory.$nouveauFichierS;
|
||||||
|
|
||||||
|
move_uploaded_file($_FILES['File']['tmp_name'], $pathToSaveF);
|
||||||
|
move_uploaded_file($_FILES['Signature']['tmp_name'], $pathToSaveS);
|
||||||
|
|
||||||
|
$resCheck = openssl_verify(file_get_contents($pathToSaveF),file_get_contents($pathToSaveS),openssl_csr_get_public_key(file_get_contents("./b/requete")));
|
||||||
|
|
||||||
|
$ok = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
<html>
|
||||||
|
<form method="POST" action="e.php" enctype="multipart/form-data">
|
||||||
|
<label for="File">Fichier : </label><input type="file" id="File" name="File" value=""/><br />
|
||||||
|
<label for="File">Signature : </label><input type="file" id="Signature" name="Signature" value=""/><br />
|
||||||
|
<input id="Envoyer" type="submit" name="Envoyer" value="Envoyer" />
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
if($ok) {
|
||||||
|
echo '<h2 style="color:#0000ff">Document intègre : ' . $resCheck . '</h2>';
|
||||||
|
} else {
|
||||||
|
echo '';
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</html>
|
BIN
TD/TD2/e/Sans titre.png
Normal file
BIN
TD/TD2/e/Sans titre.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 163 KiB |
BIN
TD/TD2/e/image0.gif
Normal file
BIN
TD/TD2/e/image0.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 382 KiB |
BIN
TD/TD2/e/signature
Normal file
BIN
TD/TD2/e/signature
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user