<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Serhat Sönmez on Medium]]></title>
        <description><![CDATA[Stories by Serhat Sönmez on Medium]]></description>
        <link>https://medium.com/@serhattsnmz?source=rss-bd2564f57171------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*CCRrIPMLPnDXgtKk.jpg</url>
            <title>Stories by Serhat Sönmez on Medium</title>
            <link>https://medium.com/@serhattsnmz?source=rss-bd2564f57171------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 23:07:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@serhattsnmz/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Securing File Upload & Download with Using AWS S3 Bucket Presigned URLs and Python Flask]]></title>
            <link>https://medium.com/@serhattsnmz/securing-file-upload-download-with-using-aws-s3-bucket-presigned-urls-and-python-flask-a5c372436f6?source=rss-bd2564f57171------2</link>
            <guid isPermaLink="false">https://medium.com/p/a5c372436f6</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[presigned-url]]></category>
            <category><![CDATA[s3-bucket]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[flask]]></category>
            <dc:creator><![CDATA[Serhat Sönmez]]></dc:creator>
            <pubDate>Thu, 13 Jan 2022 10:45:04 GMT</pubDate>
            <atom:updated>2022-05-06T18:08:13.673Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/660/1*5YvALgJwsIEp2iIQLtky9A.png" /></figure><p>AWS S3 Buckets are a great way to store data for web applications, especially if the data files are big. But how can we grant access “public web application users” to upload files to “private S3 buckets” or download from there? How can we make sure our Bucket is safe and no one else sees the other files that they are not authorized to? In the following sections, we will learn secure ways to upload or download data from private S3 Buckets while creating a simple Python Flask web application.</p><p><a href="https://github.com/serhattsnmz/aws-s3-bucket-example">Check out the example project on Github</a>.</p><p><strong><em>List of content:</em></strong><br><em>1. What is AWS S3 Bucket?<br>2. Who can access the objects in AWS S3 Bucket?<br>3. What is “Presigned URL”?<br>4. Creating AWS S3 Bucket<br>5. Creating AWS IAM user and limit the permissions<br>6. Creating Python module for Bucket processes<br>7. Creating Flask application<br>8. Creating HTML page and AJAX endpoints<br>9. How can we make accessing Bucket objects more secure?</em></p><h3>What is AWS S3 Bucket?</h3><p>An AWS S3 (Amazon Simple Storage Service) is an online object storage service and offers scalability, data availability, security, and performance. The “Buckets”, similar to file folders, can store objects (any type of data file) and their descriptive metadata.</p><p>A Bucket is used to store objects and the objects are defined by “Key” which simply means filename. If a bucket is public and someone wants to reach the object in it, `https://s3.amazonaws.com/&lt;bucket&gt;/&lt;key&gt;` can be used.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/895/1*vWmHaqZiZCakYMRGvDUCTg.png" /></figure><h3><strong>Who can access the objects in AWS S3 Bucket?</strong></h3><p>It depends on who you are allowing access to. Buckets can be created as Private and Public privileges. If it is created as Public, anyone can access the bucket and objects in it. Otherwise, if it is created as Private, only allowed users can access data and the users can be chosen via AWS IAM (Identity and Access Management). With IAM, user authorization can also be set, which is named “Policies”.</p><h3><strong>What is “Presigned URL”?</strong></h3><p>Presigned URLs can be used to upload, download or delete files by people who don’t have any access to the bucket. Presigned URLs grant temporary access to specific S3 objects and can only be created by users who have persistent access.</p><p>Using presigned URLs provides many important advantages:</p><ul><li>Bucket doesn’t need to be public, so private data (like users’ private files on a web application) can be stored securely in the same bucket.</li><li>If a user, who doesn’t have access to the bucket, wants to upload or download data; they still can download or upload data via presigned URLs.</li><li>Presigned URLs can be created at the server-side, so users cannot access sensitive data like API keys and cannot create URLs by themselves.</li><li>Presigned URLs cannot be changed and are time-limited. So a user, who has the presigned URL of an object, cannot access another object by changing the signature of the URL and cannot use this URL forever.</li></ul><h3><strong>Creating AWS S3 Bucket</strong></h3><p>First, let’s create an AWS S3 Bucket. Navigate to <a href="https://s3.console.aws.amazon.com/s3/home">AWS S3 Bucket</a> and click the “Create bucket” button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0BuS7k5LvE5r_j97Nn9M4g.png" /></figure><ol><li>Select bucket name, it must be unique (<a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucketnamingrules.html">check out the naming rules</a>)</li><li>Select AWS Region or leave it as default.</li><li>Select ACLs disabled for Object Ownership.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/872/1*_XjoGV0A5y48-qcPDmGdPA.png" /></figure><p>4. Make sure “Block all public access” is checked. This makes S3 Bucket private and only the users we grant access can reach the bucket. We will create access granted users later on AWS IAM.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/829/1*PYRi3aCNMAIwXLutli-ONg.png" /></figure><p>5. Leave the other sections as default.</p><p>6. Click the “Create Bucket” button.</p><h3><strong>Creating AWS IAM user and limit the permissions</strong></h3><p>The second thing we need to do is create an IAM user which will have limited access to the S3 Bucket we’ve been created. After creating a user, we will get access credentials (Access Key ID and Secret Access Key) and we will use that information in our web application.</p><p>Let’s create a policy to define permissions for the user we will create later.</p><p>1. Go to <a href="https://console.aws.amazon.com/iam/home">AWS IAM Homepage</a>, select Policies, and click the “Create Policy” button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c7K1h7S2ufUDnDBoB88IcA.png" /></figure><p>2. Select “S3” in the “Service” section,</p><p>3. Select the following permissions in the “Action” section. If you don’t need to have some of the permissions, you don’t have to select them.</p><ul><li><em>ListBucket </em>: For listing files in Bucket</li><li><em>GetBucketLocation </em>: For listing files in Bucket</li><li><em>GetObject </em>: Download object permission</li><li><em>DeleteObject </em>: Delete object permission</li><li><em>PutObject </em>: Upload object permission</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bhObYccbgS-IsHpLNLUYFw.png" /></figure><p>4. In the “Resources” section, we should choose which S3 Bucket we grant permission to the user to use. We can choose all buckets, but we will limit the user to use only the bucket we’ve created before. So, write bucket name and choose “Any” for objects.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/1*VzKWUJtkmwrbtMSeOi7Jsg.png" /></figure><p>5. Leave the other section as default and next to the other steps. Lastly, name the policy and click the “Create policy” button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*moctgqfumqHXLaFt7Xitqw.png" /></figure><p>After creating a user policy, we can create a user who will manage Bucket processes.</p><p>1. Go to <a href="https://console.aws.amazon.com/iam/home">AWS IAM Homepage</a>, select “Users” and click the “Add users” button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jp1ZHk_aQeM1hgyX5eIzkQ.png" /></figure><p>2. Name the user and select “Access key - Programmatic access” and click the “Next” button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/994/1*k1ihWefUjsrEHIt_KjBIFw.png" /></figure><p>3. For permissions, select “Attach existing policies directly”, find and select the policy we’ve created before, then click the “Next” button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PbXondLpWqcglDyDROXhhw.png" /></figure><p>4. Leave the other sections as default and create the user. After that, AWS shows “Access key ID” and “Secret access key”. The AWS access credentials <strong><em>must be</em></strong> noted for later use.</p><h3><strong>Creating Python module for Bucket processes</strong></h3><p>After creating S3 Bucket and IAM User, we can start programming our web application. The application will use the Python Flask library as the backend for serving data and JQuery for Ajax requests.</p><p>Firstly, we will create a lib.pyfile and insert a class that is responsible for downloading and uploading files to our AWS Bucket. We will use the Boto3, the official AWS Python module (<a href="https://boto3.amazonaws.com/v1/documentation/api/latest/index.html">Boto3 Documentation</a>).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e40d21c95e1b2b728c6a657e35f0ed2c/href">https://medium.com/media/e40d21c95e1b2b728c6a657e35f0ed2c/href</a></iframe><p>The code above has a class named AwsBucketApiand two functions in it. get_settingsmethod reading settings.jsonfile; getting AWS credentials, bucket name, and bucket region. The JSON file should be like that:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ed1c249201e2e0c7eadc1bc8e1cc421b/href">https://medium.com/media/ed1c249201e2e0c7eadc1bc8e1cc421b/href</a></iframe><p>The __init__function creates the self.bucket object that indicates which AWS service and credentials we will use. In the following functions, we will use that object to connect S3 Bucket.</p><h4><strong>Presigned URL for getting file</strong></h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/403fd367b5f599148d44d9fe866c4a73/href">https://medium.com/media/403fd367b5f599148d44d9fe866c4a73/href</a></iframe><p>This method gets a filename (filenames are defined as <strong><em>Key </em></strong>on AWS) and returns a presigned URL string. We can show that URL to the user who we want to access the file. Normally all objects are private (we define that when creating the bucket), yet we will create a temporary public URL (the URL is time-limited, look at the expires) and anyone who has the URL can access data. As you can see in the .generate_presigned_url() function, we define bucket name and filename at the beginning, so if someone changes the signature of created URL, cannot reach any other bucket or objects.</p><h4><strong>Presigned URL for uploading file</strong></h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/43fa2b589001e3652a856fc32dd63ba1/href">https://medium.com/media/43fa2b589001e3652a856fc32dd63ba1/href</a></iframe><p>Same as the presigned get URL, the method above will create a URL for public upload and some other fields. We will create a form and we will use the url value as action url, the fields values as hidden inputs. As before, we will grant users to upload files to the bucket who normally don’t have any permissions for that.</p><h4><strong>List and Delete Functions</strong></h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2717e2a56f72117b72d8c3edf3de41bc/href">https://medium.com/media/2717e2a56f72117b72d8c3edf3de41bc/href</a></iframe><p>These methods are not relevant to the <strong><em>presigned URL</em></strong> concept, but it’d be better to have. Presigned URLs are used just for two actions: <strong><em>Upload file</em></strong> and <strong><em>get/download file</em></strong>. All other processes (like listing or deleting files) must be done at the backend and user permissions must be checked by the programmer. For example, with the delete_file method, if a user sends a filename that belongs to someone else, the method will delete the file; so before doing that, user permissions must be checked.</p><h3><strong>Creating Flask application</strong></h3><p>The Flask application basically has 3 endpoints:</p><ul><li>/ : Homepage. It returns the `index.html` file which has file upload form and user file list. (In this example we will only use image files.)</li><li>/get_images : Ajax endpoint to get user files. It returns a dict object which includes `filename` and presigned get `url`</li><li>/delete_images : Ajax endpoint to delete file. It gets a filename and deletes the file.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1594272c22624d464fba2f471d6a61a6/href">https://medium.com/media/1594272c22624d464fba2f471d6a61a6/href</a></iframe><h3><strong>Creating HTML page and AJAX endpoints</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v47zExsaTISWHZcrEwnvzg.png" /></figure><p>The last step is creating `index.html` file and using the methods above in that HTML page with Ajax methods. Full code is down below and has these sections:</p><ol><li>section-1: This section has a form for uploading files. The homepage() method in main.py file gets presigned post fields by using generate_presigned_post_fields() method in lib.py file, and the method returns a dictionary that has presigned post url(https://medium.com/str) and signature fields(dict). For creating the upload form; we should include that fields as hidden inputs (keys are input name and values are input value) and use url as action URL.</li><li>section-2: This is a basic image list section which is filled by ajax at section-3.</li><li>section-3: This ajax method sends a request to the /get-images endpoint and gets a list of dict which has presigned get url(https://medium.com/str) and filename(str). If ajax is successful, it places the data in the table at section-2.</li><li>section-4: This ajax method serializes form data at section-1 and sends it to the presigned post URL which was created before and placed to the action property of the form.</li><li>section-5: This ajax method is responsible for deleting files.</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a25555d7213d9b0573ae7b85a7b9666b/href">https://medium.com/media/a25555d7213d9b0573ae7b85a7b9666b/href</a></iframe><h3><strong>How can we make accessing Bucket objects more secure?</strong></h3><h4><strong>Cross-origin resource sharing (CORS)</strong></h4><p>AWS S3 has CORS (Cross-origin resource sharing) configuration support. CORS defines a way for client web applications that are loaded in one domain to interact with resources in a different domain. With S3 CORS configuration support, we can;</p><ul><li>identify the origins that we will allow to access our bucket</li><li>specify HTTP methods to allow</li><li>limit the post or get header keys</li><li>define max-age in seconds for browsers can cache the response.</li></ul><blockquote>The detailed documentation is <a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/enabling-cors-examples.html">here</a> and <a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/ManageCorsUsing.html#cors-allowed-methods">here</a>.</blockquote><p>To add a CORS configuration to an S3 bucket,</p><ol><li>In the Buckets list, choose the name of the bucket that you want to create a bucket policy for.</li><li>Choose Permissions.</li><li>In the Cross-origin resource sharing (CORS) section, choose Edit.</li><li>In the CORS configuration editor text box, type or copy and paste a new CORS configuration, or edit an existing configuration. The CORS configuration is a JSON file. The text that you type in the editor must be valid JSON.</li><li>Choose Save changes.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/897/1*m2zBAPE_K3hgUKq3P2muTQ.png" /></figure><h4><strong>Bucket policy</strong></h4><p>Bucket policy is another way to limit resources, actions and define conditions. For more information check out <a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/access-policy-language-overview.html">Policies and Permissions in Amazon S3</a>.</p><p>Serhat Sönmez<br>Software Team Lead<br><a href="https://serhatsonmez.com.tr/">https://serhatsonmez.net</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a5c372436f6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GPG (GnuPG) Nedir? Git Commit’leri GPG ile nasıl imzalanır?]]></title>
            <link>https://medium.com/codehane/gpg-gnupg-nedir-git-commitleri-gpg-ile-nas%C4%B1l-imzalan%C4%B1r-2f8158f0cb2d?source=rss-bd2564f57171------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f8158f0cb2d</guid>
            <category><![CDATA[git]]></category>
            <category><![CDATA[şifreleme]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[gpg]]></category>
            <category><![CDATA[gitlab]]></category>
            <dc:creator><![CDATA[Serhat Sönmez]]></dc:creator>
            <pubDate>Tue, 20 Feb 2018 17:15:52 GMT</pubDate>
            <atom:updated>2019-12-25T19:09:11.255Z</atom:updated>
            <cc:license>http://creativecommons.org/publicdomain/zero/1.0/</cc:license>
            <content:encoded><![CDATA[<p>Bu yazımızda GPG’nin ne olduğundan, GPG ile şifreleme ve imzalamanın nasıl yapıldığından ve git ile çalışırken commitlerimizi nasıl GPG ile imzalayacağımızdan bahsedeceğiz.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*jFootiAaNi_Qk6XRPB-E6g.png" /></figure><h4>GPG Nedir?</h4><p>GPG ( GnuPG — GNU Privacy Guard); GPL lisansına sahip, açık kaynak kodlu bir OpenPGP şifreleme standartıdır. OpenPGP ise, izni olmayan kişilerin görmesini istemediğiniz her türlü verinin bütünlüğünü ve güvenliğini sağlayan bir protokoldür. (Protokolün detaylarına <a href="https://tools.ietf.org/html/rfc4880">buradan</a> ulaşabilirsiniz.) Basit olarak herhangi bir datanın şifrelenmesini ve çözülmesini kapsar. OpenPGP standartını oluşturan şifreleme ve anahtarlama yöntemi, 1991 yılında Philip Zimmermann tarafından geliştirilen PGP (<em>Pretty Good Privacy</em>) programına dayanır.</p><p>GPG şifrelemesinden bahsetmeden önce, klasik şifreleme ve bu şifrelemenin dezavantajından bahsetmekte fayda var.</p><p>Klasik şifreleme yönteminde, datalar şifrelenirken bir parola belirlenir ve bu parola şifrelenirken kullanılmasının yanında, şifrelenmiş datanın çözülmesinde de kullanılması gerekir. Bu yöntemle şifrelediğiniz datayı gönderdiğiniz başka bir kullanıcının bu dataya erişimini sağlamasını istiyorsanız, parolayı da bu kullanıcıya ulaştırmanız gerekmektedir. Fakat bu yöntem, eğer aranızdaki iletişimi dinleyen biri varsa (Man-in-the-middle attacks gibi) güvenilmezdir. Çünkü aradaki iletişimi çözen kimse, şifrelenmiş dataya ulaşabildiği gibi, parolaya da ulaşacak ve dataya çözebilecektir. Böyle olunca da datanın şifrelenmesi hiçbir anlam ifade etmeyecektir.</p><p>Yukarıda bahsettiğimiz sorunun aslında çok basit bir çözüm yolu var: İki tane anahtar oluşturmak. GPG tam bu anda devreye girmektedir. Bu iki tane anahtardan biri datayı şifrelemek için kullanılırken (public key), diğer anahtar, public key ile şifrelenmiş datanın çözülmesinde kullanılmaktadır (private key). Bu anahtarlardan public key, adından da anlaşılacağı üzere, herkese açık olarak yayınlanabilir, fakat private key’in size özel kalması ve kimseyle paylaşmamanız gerekmektedir. Herhangi biri size bir data göndermek istediği zaman (dosya, mail, yazı vs.) açıktan paylaştığınız public key ile bunu datayı şifreleyebilir ve siz de private key ile bu datayı çözebilirsiniz. Private key sadece sizde olduğu için, datanın sizden başkası tarafından açılmadığından emin olabilirsiniz.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*LpV5okf8ByND-ClSQZ7-aA.png" /></figure><h4>Şifreleme ve İmzalama Arasındaki Farklar</h4><p>Şifreleme ve imzalama birbirine karıştırılan önemli iki kavramdır. Farkları ise şunlardır :</p><ul><li>Şifreleme yaptığınızda, <strong>başka birinin public key</strong>’ini kullanırsınız ve datayı yolladığınız kişi bu datayı çözmek için <strong>kendi private key</strong>’ini kullanır.</li><li>İmzalama yaptığınızda, <strong>kendi private key</strong>’iniz ile <strong>kendi verinizi </strong>imzalarsınız ve datayı yolladığınız kişi <strong>sizin public key</strong>’inizi kullanarak, datanın gerçekten sizden gelip gelmediğini çözümler.</li></ul><p>Bu ayrımlar ışığında, eğer bir kişiye bir data gönderiyor ve sadece bu kişinin bu datayı aldığından emin olmak istiyorsanız <strong><em>şifreleme, </em></strong>kamuya bir data paylaşıyor ve bu datayı alanların, datanın kaynağının siz olduğundan emin olmasını istiyorsanız <strong><em>imzalama </em></strong>kullanmalısınız.</p><h4>GPG Kurulumu</h4><p>GPG ile ilgili tüm kütüphane GUI arayüz programlarına <a href="https://www.gnupg.org/software/">buradan</a> ulaşabilirsiniz. Bunlar dışında birçok açık kaynak mail istemcisi ( <em>Evolution</em>, <em>KMail</em> vs.) GPG kullanarak mail alıp gönderme hizmetini vermektedir.</p><p>Birçok linux dağıtımı, içinde GPG ile birlikte gelmektedir. Sisteminizde GPG olup olmadığını kontrol etmek için şu komutu çalıştırabilirsiniz:</p><pre><strong>╰─λ gpg --version</strong></pre><p>Eğer GPG sisteminizde kurulu değilse <a href="https://gnupg.org/download/">buradan</a> Linux, Windows ve MacOS için uygun sürümünü indirebilirsiniz.</p><h4>Varolan Key Kontrolü</h4><p>Sisteminizde daha önceden yaratılmış bir GPG key çifti olup olmadığını kontrol etmek için aşağıdaki kodu konsol üzerinden çalıştırabilirsiniz. Eğer key çifti varsa listenelecektir.</p><pre><strong>╰─λ gpg --list-keys</strong></pre><h4>Anahtar Yaratmak ve Kullanmak</h4><pre><strong>╰─λ gpg --gen-key</strong><br>gpg (GnuPG) 1.4.20; Copyright (C) 2015 Free Software Foundation, Inc.<br>This is free software: you are free to change and redistribute it.<br>There is NO WARRANTY, to the extent permitted by law.</pre><pre>Please select what kind of key you want:<br>   (1) RSA and RSA (default)<br>   (2) DSA and Elgamal<br>   (3) DSA (sign only)<br>   (4) RSA (sign only)<br><strong>Your selection? 1</strong><br>RSA keys may be between 1024 and 4096 bits long.<br><strong>What keysize do you want? (2048) 4096</strong><br>Requested keysize is 2048 bits<br>Please specify how long the key should be valid.<br>         0 = key does not expire<br>      &lt;n&gt;  = key expires in n days<br>      &lt;n&gt;w = key expires in n weeks<br>      &lt;n&gt;m = key expires in n months<br>      &lt;n&gt;y = key expires in n years<br><strong>Key is valid for? (0) 0</strong><br>Key does not expire at all<br><strong>Is this correct? (y/N) y</strong></pre><pre>You need a user ID to identify your key; the software constructs the user ID<br>from the Real Name, Comment and Email Address in this form:<br>    &quot;Heinrich Heine (Der Dichter) &lt;<a href="/service/mailto:heinrichh@duesseldorf.de">heinrichh@duesseldorf.de</a>&gt;&quot;</pre><pre><strong>Real name: Serhat Sönmez<br>Email address: mail@mail.com<br>Comment: Software Developer</strong></pre><pre><strong>Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O</strong><br>You need a Passphrase to protect your secret key.</pre><pre><strong>Enter passphrase:</strong></pre><pre>gpg: gpg-agent is not available in this session<br>We need to generate a lot of random bytes. It is a good idea to perform<br>some other action (type on the keyboard, move the mouse, utilize the<br>disks) during the prime generation; this gives the random number<br>generator a better chance to gain enough entropy.<br>...</pre><p>GPG key oluşturmak için komut satırına gpg --gen-key komutunu giriyoruz. Komutu çalıştırdığınızda size bazı sorular soracaktır:</p><ul><li>İlk sorulan soru, key yaratılırken hangi tür algoritma kullanılcağıdır. Algoritmaların detaylarına <a href="https://tools.ietf.org/html/rfc4880#section-9.1">buradan</a> ulaşabilirsiniz. Default algoritma seçilip geçilebilir.</li><li>Daha sonra key uzunluğu sorulacak. Daha güvenli olaması açısından en yüksek boyut seçilebilir.</li><li>3. olarak, keylerin son kullanım tarihini oluşturmak istiyorsanız bunu seçebilirsiniz veya 0 seçerek son kullanım tarihi tanımlanmasını atlayabilirsiniz. Sonrasında bunu tekrar onaylamanızı isteyebilir.</li><li>Sonraki adımda kişisel bilgilerinizi tanımlamanızı isteyecektir. Bu bilgiler birleştirilip bir User ID oluşturacak (örn: “Heinrich Heine (Der Dichter) &lt;heinrichh@duesseldorf.de&gt;”) ve public key içerisine eklenecektir. Bu bilgiler, public key’inizi kullanmak isteyen kişilere sizi tanıtmada yardımcı olacaktır. Bilgileri girdikten sonra onaylamanızı isteyecektir, “O” girerek onaylayabilirsiniz. User ID bilgisinin public key içinde gösterimi :</li></ul><pre>...<br>0000520 311 343 271  \0 021 001  \0 001<br>0000528 264   3   <strong>S   e   r   h   a   t<br>0000536       S 303 266   n   m   e   z<br>0000544       (   S   o   f   t   w   a<br>0000552   r   e       D   e   v   e   l<br>0000560   o   p   e   r   )       &lt;   m<br>0000568   a   i   l   @   m   a   i   l<br>0000576   .   c   o   m   &gt;</strong> 211 002   8<br>0000584 004 023 001 002  \0   &quot; 005 002<br>...</pre><ul><li>Kişisel bilgilerinizi düzgün ve eksiksiz girdikten sonra, sizden bir parola girmeniz ve doğrulamanız isteyecektir. Bu parola, kendi bilgisayarınızda depolanacak private key’in güvenliği için gereklidir. Private key kullanılırken sizden yine bu parolayı girmenizi isteyecektir. Güçlü bir parola seçmeniz güvenliğiniz açısından iyi olacaktır.</li></ul><p>Bu bilgileri girdiyseniz, bundan sonra key’iniz oluşturulmaya başlanacaktır. Oluşturulan key tamamen random byte karakterlerinden oluşacağı ve o anda üretileceği için, key oluşturulana kadar sizden random hareket etmenizi isteyecektir (Mause hareketi, keybord ile random karakter girme veya diski kullanan herhangi bir işlem yapma).</p><pre>We need to generate a lot of random bytes. It is a good idea to perform<br>some other action (type on the keyboard, move the mouse, utilize the<br>disks) during the prime generation; this gives the random number<br>generator a better chance to gain enough entropy.</pre><p>Tüm bu işlemler başarıyla geçildiğinde private ve public key’leriniz /home/&lt;user&gt;/.gnupg altında oluşturulmuş olacaktır.</p><h4>GPG User ID Değiştirme</h4><p>Oluşturduğunuz GPG dosyalarındaki User ID kısımlarını daha sonra değiştirebilirsiniz. Bunun için öncelikle sistemdeki key’leri listeleyip değiştirmek istediğiniz key’in ID’sini almanız gerekir.</p><pre><strong>╰─λ gpg --list-keys --keyid-format long<br></strong>/home/serhat/.gnupg/pubring.gpg<br>-------------------------------<br>pub   4096R/<strong><em>705A56F8F4EE61F6</em></strong> 2018-02-20 [expires: 2018-04-21]<br>uid   Serhat Sönmez (Software Developer) &lt;<a href="/service/mailto:ssonmez@live.com">m</a>ail@mail.com&gt;<br>sub   4096R/18FF5E291D61C1EB 2018-02-20 [expires: 2018-04-21]</pre><p>Daha sonrasında gpg --edit-key 705A56F8F4EE61F6 komutunu yazıp, adduid komutuyla bilgileri tekrardan girebilirsiniz.</p><pre><strong>╰─λ gpg --edit-key 705A56F8F4EE61F6</strong><br>gpg (GnuPG) 1.4.20; Copyright (C) 2015 Free Software Foundation, Inc.<br>This is free software: you are free to change and redistribute it.<br>There is NO WARRANTY, to the extent permitted by law.</pre><pre><strong>gpg&gt; adduid</strong><br>Real Name: <em>Yeni İsim</em><br>Email address: <em>yenisim@github.com</em><br>Comment: <em>GitHub key</em><br>Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit?</pre><h4>Public Key Dosyası Oluşturmak</h4><p>gpg --list-keys --keyid-format long komutuyla, daha önce oluşturulmuş key’ler görülebilir. Buradaki pub kısmı yanında bulunan id kısmını alıp, public key oluşturabiliriz.</p><pre><strong>╰─λ gpg --list-keys --keyid-format long<br></strong>/home/serhat/.gnupg/pubring.gpg<br>-------------------------------<br>pub   4096R/<strong>99C0A0DD37141AF5</strong> 2018-02-20<br>uid   Serhat Sönmez (Software Developer) &lt;<a href="/service/mailto:mail@mail.com">mail@mail.com</a>&gt;<br>sub   4096R/53ECA83A41BF4A75 2018-02-20</pre><p>gpg --armor --export 99C0aODD37141AF5 komutuyla public key oluşturulabilir. Public key uzunluğu, oluştururken seçtiğiniz ayarlara göre değişkenlik gösterebilir. Komutun çıktısındaki --BEGIN-- ve --END-- blokları arasındaki kısmı kopyalayıp public key olarak kullanabilirsiniz.</p><pre><strong>╰─λ gpg --armor --export 99C0A0DD37141AF5</strong><br>-----BEGIN PGP PUBLIC KEY BLOCK-----<br>Version: GnuPG v1</pre><pre>mQINBFqMG74BEACjlhbQ5bw165td72bhs57BQKxUmABII6Xge3Ib3I8QEobRkblQ<br>ahfxLUpRrNHS6CcELCw+huB4/cLcL9tCIshqpEfhlNzQ8rppSLAiE+EDi7CbZnp2<br>Vrm1XV+liWnJvu352lz2sdVkSw3PpEhtCj+ssIiVnpjkayPM17H1mrGwUpZWoGuj<br>s47hc79/J18kxM7gG8GW+T0IsPZwxwctbaXZdn/N4Jkch7xFndGSD44+Lcy2obW6<br>...<br>-----END PGP PUBLIC KEY BLOCK-----</pre><p>Eğer oluşturduğunuz public key’i bir dosyada tutmak istiyorsanız gpg -a -o &lt;fileName&gt; --export &lt;KeyID&gt; komutunu kullanabilirsiniz. Bu komut ile, bulunduğunuz dizinde &lt;fileName&gt; kısmına yazdığınız isimle, public key dosyası oluşacaktır.</p><pre><strong>╰─λ gpg -a -o myPublicKey.txt --export 99C0A0DD37141AF5</strong></pre><h4>GPG İle Data Şifreleme ve Şifreli Dosyayı Çözme</h4><p>GPG kullanılarak çok basit bir şekilde dosyaları şifreleyebilir ve çözebilirsiniz. Herhangi bir dosyayı şifrelemek için yapmanız gereken tek şey gpg -r &lt;KeyID&gt; -e &lt;dosyaAdi&gt; komutunu çalıştırmaktır. Buradaki -r parametresi, hangi kullanıcı ile imzalamak istiyorsak onu seçtiğimiz yerdir. Sistemimizde bulunan keyleri listeleyebilir ve bunların ID’lerinden birini şifreleme için kullanabiliriz.</p><pre><strong>╰─λ ls</strong><br>deneme.txt</pre><pre><strong>╰─λ cat deneme.txt</strong><br>Serhat Sönmez</pre><pre><strong>╰─λ gpg -r 705A56F8F4EE61F6 -e deneme.txt</strong></pre><pre><strong>╰─λ ls</strong><br>deneme.txt  <em>deneme.txt.gpg</em></pre><p>Oluşturulan şifrelenmiş dosyayı çözmek de aynı derece basittir. gpg -o &lt;outputFilePath&gt; -d &lt;cryptedFile&gt; kodunu kullanarak, şifrelenmiş dosya açılabilir. Dosya çıkarılırken size, daha önce GPG key&#39;leri oluştururken girdiğiniz parola sorulacaktır. -o parametresini girmeyerek, içeriğin sadece konsol üzerinden okunmasını sağlayabilirsiniz.</p><pre><strong>╰─λ ls</strong><br>deneme.txt.gpg</pre><pre><strong>╰─λ gpg -o cikti.txt -d deneme.txt.gpg</strong></pre><pre><strong>╰─λ ls</strong><br><em>cikti.txt</em>  deneme.txt.gpg</pre><pre><strong>╰─λ cat cikti.txt</strong><br>Serhat Sönmez</pre><h4>GPG ile Data İmzalama ve İmza Kontrolü</h4><p>Daha önce de bahsettiğimiz gibi, herhangi bir verinin sizden geldiğini göstermek istiyorsanız, o veriyi GPG ile imzalayabilirsiniz. Basit bir şekilde gpg -s &lt;file&gt; komutuyla imzalama yapabilirsiniz. Bu komut sonucunda .gpg uzantılı, imzalanmış bir dosya oluşacaktır. Bu dosya oluşturulurken sıkıştırma kullanıldığından okunabilir değildir. Okunabilir şekilde dosya imzalamak için gpg --clearsign &lt;file&gt; komutunu kullanabilirsiniz.</p><pre><strong>╰─λ ls</strong><br>cikti.txt</pre><pre><strong>╰─λ gpg --clearsign cikti.txt</strong></pre><pre><strong>╰─λ ls</strong><br>cikti.txt <em>cikti.txt.asc</em></pre><pre><strong>╰─λ cat cikti.txt.asc</strong><br>-----BEGIN PGP SIGNED MESSAGE-----<br>Hash: SHA1</pre><pre>Serhat Sönmez<br>-----BEGIN PGP SIGNATURE-----<br>Version: GnuPG v1</pre><pre>iQIcBAEBAgAGBQJajFYMAAoJEHBaVvj07mH2npwQAJRK1Nux8vnslz8T/4e9CYoM<br>kXZ5zJza91dx+xHYZO0heCZz0H+I61d0vPbQTjApwpDY4B875PyXDYnaXoCimLC2<br>QQ4HrcB5fTV8p8Sq3i/VydJP8HBSe7fxc7gF22sgBIzvJWmekY3TrMrzFGwSLMAy<br>aDi1UXCIZREpZk6sNVmxycdYUXomVHt4nLo0S8c2TyKpFhHjPw5+cpTwQy8oiqrb<br>41d2KVmPUkYjR7dR5FpiEwOvR19l9rFwYp1bE6KlSIEhQZhk7ADvWtBIUivjbmlF<br>8EaCleertI3Ig2yby6dTmZWrp/OliLweAcuQZL1EYsO5C2DFNrWHgCcg1VK/aotO<br>WPFjs9Q39sVycMssup1RQPVXJBML4ZM/o5B5Ds5dQsRe1fupePvQfdRssFwXfBRd<br>0+mrXCd0ALWoWoFsCWGsx5aqW/njcD0NJs49elbwYTUI8GG9AN7C0Jj8WqT6+VO1<br>b132BdA5Kz9NbYDHX/7Swi+b4qn6XiqGSWpEY1l0K5HXrs2CWr2zeLfo+gDnY350<br>JuHzMywGPeAnlaLCL7Ee9AhpDWm3Oo6rWHB2E5kv1bwYz+5RU6d7kjjQeHiUAvW3<br>CcVqx7q2p4N5g28avTqj4YnlMoK6Cu2szXNxNFszgnAXB3SZ7vOAG4Udbl9SKJV7<br>+SCOrlApMF9rVp8kaFos<br>=DogW<br>-----END PGP SIGNATURE-----</pre><p>İmzalanmış dosyanın kontrolünü yapmak için gpg --verify &lt;file&gt; komutu çalıştırılabilir.</p><pre>╰─λ gpg --verify cikti.txt.gpg<br>gpg: Signature made Tue 20 Feb 2018 08:05:06 PM +03 using RSA key ID F4EE61F6<br>gpg: Good signature from &quot;Serhat Sönmez (Software Developer) &lt;mail@mail.com&gt;&quot;</pre><h4>GPG Key Silme</h4><p>Var olan GPG anahtarlarını silmek için öncelikle secret keyi silmemiz gerekir. Daha sonrasında public keyi silerek tüm anahtarları silmiş oluruz.</p><pre><strong>╰─λ gpg --delete-secret-key &quot;Kullanıcı Adı&quot;<br>╰─λ gpg --delete-key &quot;Kullanıcı Adı&quot;</strong></pre><h4>Git Kullanırken Neden GPG İmzalama Yapmalıyım?</h4><p>GPG ile imzalanan commit’ler, sizin kimliğinizi doğrulamaktadır. GPG key’ler kişiye özel olduğu için, gelen commit’lerin gerçekten o şahıstan geldiğini doğrulamış olursunuz.</p><p>Peki imzalama hangi aşamada gerçekleşir? GPG imzalaması, <em>commit ekleme</em> aşamasında gerçekleştirilir ve <em>lokalde</em>dir. İmzalanmış commit’ler uzak server üzerine yüklenirken, daha önce uzak server üzerine yüklediğiniz GPG public key ile doğrulama gerçekleşir ve commit <em>verified </em>olarak işaretlenir.</p><h4>GitHub üzerine GPG Key Ekleme</h4><ul><li>Github sayfasından Settings &gt; SSH ve GPG Keys sekmesine gelerek New GPG Key butonuna tıklayınız.</li><li>Açılan pencereden, daha önce oluşturmuş olduğunuz public key’inizi kopyalayıp yapıştırınız.</li></ul><p>GPG key’iniz eklenecektir. Eğer GPG key oluştururken girmiş olduğunuz mail adresi Github hesabınızda tanımlı değilse, unverified uyarısıyla karşılacaksınız. Bunu aşmak için, ilgili mail adresini GitHub üzerine tanımlayabilir veya tanımlı mail adresinizle yeni bir GPG key oluşturup sisteme yükleyebilirsiniz.</p><h4>GitLab üzerine GPG Key Ekleme</h4><ul><li>Gitlab sayfasından Settings &gt; GPG Keys sekmesine geliniz.</li><li>Açılan pencerede direk olarak public key’inizi yapıştırınız.</li></ul><p>GPG key’iniz eklenecektir. Github’ta olduğu gibi, burada da mail adresiniz hesabınıza tanımlı değilse unverified uyarısı verecektir.</p><h4>Git Üzerine Yollanılan Commitleri İmzalama</h4><p>Öncelikle Git üzerine, oluşturdumuz GPG private key’ini tanıtmamız gerekiyor. Bunun için gpg --list-secret-keys --keyid-format long komutuyla sistemimiz üzerinde olan keylerin listesine ulaşıp, ilgili key’in ID’sini alıyoruz. Daha sonra git config --global user.signingkey &lt;ID&gt; komutuyla, ilgili GPG key’ini git üzerinde tanıtmış oluyoruz.</p><pre><strong>╰─λ gpg --list-secret-keys --keyid-format LONG</strong><br>/home/serhat/.gnupg/secring.gpg<br>-------------------------------<br>sec   4096R/705A56F8F4EE61F6 2018-02-20 [expires: 2018-04-21]<br>uid   Serhat Sönmez (Software Developer) &lt;mail@mail.com&gt;<br>ssb   4096R/18FF5E291D61C1EB 2018-02-20</pre><pre><strong>╰─λ git config --global user.signingkey 705A56F8F4EE61F6</strong></pre><p>Git üzerinde GPG tanımlaması yapıldıktan sonra, atacağımız her commit’i bu key ile imzalamamız gerekmektedir. Bunun için -S parametresini kullanacağız. Komutu çalıştırdığımda bizden, private key çözümlemesi için daha önce girdiğimiz parolayı isteyecektir. Parolayı girdikten sonra commit’imiz yapılmış olacaktır.</p><pre><strong>╰─λ git commit -S -m &lt;commit mesaji&gt;<br>╰─λ git push</strong></pre><p>Eğer her commit’inizin otomatik olarak GPG ile gönderilmesini istiyorsanız, global veya local ayarlardan gpgsign özelliğini aktif hale getirebilirsiniz.</p><pre># Global düzenleme<br>╰─λ git config --global commit.gpgsign true</pre><pre># Lokal düzenleme<br>╰─λ git config commit.gpgsign true</pre><pre># Eski haline getirme<br>╰─λ git config --global commit.gpgsign false<br>╰─λ git config commit.gpgsign false</pre><h4>Kaynaklar :</h4><ul><li><a href="https://www.openpgp.org/">https://www.openpgp.org/</a></li><li><a href="https://www.gnupg.org/">https://www.gnupg.org</a>/</li><li><a href="https://www.gnupg.org/documentation/howtos.html">https://www.gnupg.org/documentation/howtos.html</a></li><li><a href="http://irtfweb.ifa.hawaii.edu/~lockhart/gpg/">http://irtfweb.ifa.hawaii.edu/~lockhart/gpg/</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f8158f0cb2d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/codehane/gpg-gnupg-nedir-git-commitleri-gpg-ile-nas%C4%B1l-imzalan%C4%B1r-2f8158f0cb2d">GPG (GnuPG) Nedir? Git Commit’leri GPG ile nasıl imzalanır?</a> was originally published in <a href="https://medium.com/codehane">codehane</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>